forked from KDF5000/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnagram.py
More file actions
37 lines (33 loc) · 788 Bytes
/
Copy pathAnagram.py
File metadata and controls
37 lines (33 loc) · 788 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
# coding:utf-8
__author__ = 'devin'
class Solution(object):
def isAnagram(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
s_len = len(s)
t_len = len(t)
if t_len != s_len:
return False
for i in range(s_len):
if s[i] != t[t_len-i-1]:
return False
return True
def isAnagram(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
str_s = "".join(sorted(s))
str_t = "".join(sorted(t))
if str_s == str_t:
return True
return False
if __name__ == '__main__':
s = Solution()
print s.isAnagram("abc", "cba")
print sorted("bca")
print "acb" == "abc"