Back to course home
0% completed
Vote For New Content
The solution posted seems overly complicated
adi berkowitz
Nov 25, 2024
Use a hashmap
from collections import defaultdict class Solution: def isAnagram(self, s, t): # TODO: Write your code here counter = defaultdict(int) for c in s: counter[c] += 1 for c in t: if c in counter: counter[t] -= 1 else: return False return sum(counter.values()) == 0
0
0
Comments
Comments
Design Gurus10 months ago
This is O(n^2) algorithm because of the following two lines:
for c in t: if c in counter: