Skip to content

Commit 0d21b0c

Browse files
authored
Merge pull request SjxSubham#204 from LS1212-dec/lcque
242. Valid Anagram.cpp
2 parents 47756ec + afb0bfd commit 0d21b0c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

242. Valid Anagram.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
bool isAnagram(string s, string t) {
4+
if(s.length() != t.length()) return false;
5+
6+
int count[26] = {0};
7+
8+
for(int i = 0; i < s.length(); i++) {
9+
count[s[i]-'a']++;
10+
count[t[i]-'a']--;
11+
}
12+
13+
for(int i = 0; i < 26; i++) {
14+
if(count[i] != 0) return false;
15+
}
16+
17+
return true;
18+
}
19+
};

0 commit comments

Comments
 (0)