This approach tries to compare the length of the two strings after replacing the same character with ''
class Solution(object): def isAnagram(self, s, t): if len(s) != len(t) return False while len(s)>0: t = t.replace(s,'') s = s.replace(s,'') if len(s) != len(t): return False return True
isAnagram('a', 'b'). It doesn't compare the length of the strings after the first while loop, since
len(s) is already
0. You need to compare the lengths at the end of the loop.
Apart from that, great solution with even better performance.
@petroll Thanks, you are right. That's such a stupid mistake. :)