blob: 69e19d3716ad93b1cc248b90233d93829eb1cb4a (
plain)
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
|
# 242. Valid Anagram
"""
given two strings 's' and 't', return 'true' if 't' is an anagram of 's', and
false otherwise. an anagram is a word or phrase formed by rearranging the
letters of a different word or phrase, typically using all the original
letters exactly once.
"""
class Solution(object):
def isAnagram(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
sorted_s = sorted(s)
sorted_t = sorted(t)
return sorted_s == sorted_t
if __name__ == "__main__":
obj = Solution()
print(obj.isAnagram(s="anagram", t="nagaram"))
print(obj.isAnagram(s="rat", t="car"))
|