Python using defaultdict


  • 0
    Z
    class Solution(object):
    def isAnagram(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: bool
        """
        if len(s) != len(t):
            return False
        hmap = collections.defaultdict(int)
        for i in range(len(s)):
            hmap[s[i]] += 1
            hmap[t[i]] -= 1
        for x in hmap:
            if hmap[x] != 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.