diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2024-08-08 20:12:19 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2024-08-08 20:12:19 +0900 |
| commit | 0cb59e57fc21daaac47779f7a1e74dc605fa53a1 (patch) | |
| tree | d506c56db2bcc47b565c8a1bdac1bf7e9c55bfe8 /1_array_hashing | |
| parent | e8bf83d86d652c36964a2435f4a47b163e70c5bf (diff) | |
Init
Diffstat (limited to '1_array_hashing')
| -rw-r--r-- | 1_array_hashing/valid_anagram.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/1_array_hashing/valid_anagram.py b/1_array_hashing/valid_anagram.py index 1c8a1d8..9b64df3 100644 --- a/1_array_hashing/valid_anagram.py +++ b/1_array_hashing/valid_anagram.py @@ -29,14 +29,13 @@ class Solution: def hashmap(self, s: str, t: str) -> bool: if len(s) != len(t): return False + countS, countT = {}, {} + for i in range(len(s)): countS[s[i]] = 1 + countS.get(s[i], 0) countT[t[i]] = 1 + countT.get(t[i], 0) - for c in countS: - if countS[c] != countT.get(c, 0): - return False - return True + return countS == countT case1S = "apple" |
