My ACC py solution using HashTable

  • 0

    Use two hash tables to store the times every letter comes and check if the letters come with the same frequency.

    class Solution(object):
    def isAnagram(self, s, t):
        :type s: str
        :type t: str
        :rtype: bool
        if len(s) != len(t):
            return False
        sDic = {}
        tDic = {}
        for c in s:
            sDic[c] = sDic.get(c, 0) + 1
        for c in t:
            tDic[c] = tDic.get(c, 0) + 1
        for k, v in sDic.items():
            if k not in tDic or tDic[k] != v:
                return False
        return True

Log in to reply

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