SIMPLE python solution [Accepted at 96ms]

  • -2
    class Solution(object):
        def isAnagram(self, s, t):
            freq1 = self.get_freq(s)
            freq2 = self.get_freq(t)
            for c in freq1.keys() + freq2.keys():
                if freq1.get(c) != freq2.get(c):
                    return False
            return True
        def get_freq(self, s):
            """ Returns a dict with char freq map """
            char_freq = {}
            for c in s:
                if not char_freq.get(c):
                    char_freq[c] = 1
                    char_freq[c] = char_freq[c] + 1
            return char_freq

Log in to reply

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