Simple python solution

  • 0

    First make sure the two string include same letters, then count the number for each letter.

    def isAnagram(self, s, t):

        set1 = list(set(s))
        set2 = list(set(t))
        if set1 != set2:
            return False
        for char in set1:
            if s.count(char)!= t.count(char):
                return False
        return True

Log in to reply

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