-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path242_Valid_Anagram.py
More file actions
40 lines (32 loc) · 879 Bytes
/
242_Valid_Anagram.py
File metadata and controls
40 lines (32 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 9 16:32:38 2017
@author: Mac
242. Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.
For example,
s = "anagram", t = "nagaram", return true.
s = "rat", t = "car", return false.
Note:
You may assume the string contains only lowercase alphabets.
Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?
"""
import collections
class Solution(object):
def isAnagram(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
if len(s) == len(t):
return collections.Counter(s) == collections.Counter(t)
else:
return False
s = 'anagram'
t = 'nagaram'
test = Solution()
res = test.isAnagram(s,t)
print (res)