Accepted 1 line python solution(Beat 96%, 3 options)


  • 0
    Z
    def isAnagram(self, s, t):
        #return sort(s) == sort(t)    #accepted but maybe O(nlogn) depend on the implementation behind sort()  80ms
        #return { i: s.count(i) for i in s} == { i: t.count(i) for i in t}   #right but time exceeds so not accepted
        return { i: s.count(i) for i in set(s)} == { i: t.count(i) for i in set(t)}  #accepted O(n) 40ms

Log in to reply
 

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