Simple Python solution beats 97.8%


  • 0
    Y
    from collections import defaultdict
    class Solution(object):
        def isAnagram(self, s, t):
            """
            :type s: str
            :type t: str
            :rtype: bool
            """
            d = defaultdict(int)
            for c in s:
                d[c] += 1
            for c in t:
                d[c] -= 1
            for v in d.values():
                if v != 0:
                    return False
            return True
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.