242. Valid Anagram
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 13, 2024
Last updated : July 01, 2024
Related Topics : Hash Table, String, Sorting
Acceptance Rate : 65.77 %
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
cntS, cntT = Counter(s), Counter(t)
if not cntS == cntT :
return False
for key in cntS :
if cntS.get(key) != cntT.get(key) :
return False
return True
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
return (len(s) == len(t)) and (Counter(s) == Counter(t))
bool isAnagram(char* s, char* t) {
int letters[26] = {0};
while (*s) {
letters[*s - 'a']++;
s++;
}
while (*t) {
letters[*t - 'a']--;
t++;
}
for (int i = 0; i < 26; i++) {
if (letters[i]) {
return false;
}
}
return true;
}