242. Valid Anagram
Input:
s = "anagram",
t = "nagaram"
Output: trueInput:
s = "rat",
t = "car"
Output: falseLast updated
Was this helpful?
Input:
s = "anagram",
t = "nagaram"
Output: trueInput:
s = "rat",
t = "car"
Output: falseLast updated
Was this helpful?
Was this helpful?
class Solution(object):
def isAnagram(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
return sorted(s) == sorted(t)class Solution(object):
def isAnagram(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
d = collections.defaultdict(int)
for c in s: d[c]+= 1
for c in t: d[c]-= 1
return all(d[v] == 0 for v in d)