Python beat 80.11% solution


  • 0
    I
        def isAnagram(self, s, t):
            """
            :type s: str
            :type t: str
            :rtype: bool
            """
            a = {}
            for x in s:
                if x not in a:
                    a[x] = 1
                else:
                    a[x] += 1
            for x in t:
                if x not in a:
                    return False
                else:
                    a[x] -= 1
                    if a[x] < 0:
                        return False
            for x in a:
                if a[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.