Skip to content

Commit 25e7607

Browse files
committed
fix review comments
1 parent e90a360 commit 25e7607

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

valid-anagram/jylee2033.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ def isAnagram(self, s: str, t: str) -> bool:
77
# Build a hashmap counting characters in t
88
char_count = {}
99

10+
# for letter in t:
11+
# if letter not in char_count:
12+
# char_count[letter] = 1
13+
# else:
14+
# char_count[letter] += 1
15+
1016
for letter in t:
11-
if letter not in char_count:
12-
char_count[letter] = 1
13-
else:
14-
char_count[letter] += 1
17+
char_count[letter] = char_count.get(letter, 0) + 1
1518

1619
# Decrease counts using characters from s
1720
for letter in s:
@@ -25,3 +28,6 @@ def isAnagram(self, s: str, t: str) -> bool:
2528
return False
2629

2730
return True
31+
32+
# Time Complexity: O(n)
33+
# Space Complexity: O(1) since the hashmap stores at most 26 letters

0 commit comments

Comments
 (0)