Skip to content

Commit 5e38b0b

Browse files
committed
Solution: Valid Anagram
- rewrite in cpp
1 parent 2973412 commit 5e38b0b

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

valid-anagram/flynn.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* For length of given strings N,
3+
*
4+
* Time complexity: O(N)
5+
* - iteration for given strings
6+
*
7+
* Space complexity: O(1)
8+
* - the size of the container `count` is constant
9+
*/
10+
11+
class Solution {
12+
public:
13+
bool isAnagram(string s, string t) {
14+
int count[26] = {0};
15+
16+
for (auto c : s) count[c - 'a']++;
17+
for (auto c : t) count[c - 'a']--;
18+
19+
for (int i = 0; i < 26; i++) if (count[i]) return false;
20+
return true;
21+
}
22+
};

valid-anagram/flynn.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)