Skip to content

Commit f644e1f

Browse files
committed
solved Valid Anagram
1 parent e6206a0 commit f644e1f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

valid-anagram/wclee2265.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// https://leetcode.com/problems/valid-anagram/
2+
3+
class Solution {
4+
public:
5+
bool isAnagram(string s, string t) {
6+
int cnt1[26]={0,}, cnt2[26] = {0,};
7+
for(char c : s) cnt1[c-'a']++;
8+
for(char c : t) cnt2[c-'a']++;
9+
10+
for(int i=0; i<26; i++) {
11+
if(cnt1[i] != cnt2[i]) return false;
12+
}
13+
14+
return true;
15+
}
16+
};

0 commit comments

Comments
 (0)