Created
October 13, 2020 13:52
-
-
Save u8989332/5076d945a485e35327948280e555a536 to your computer and use it in GitHub Desktop.
LeetCode - 242 Valid Anagram
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
class Solution { | |
public: | |
bool isAnagram(string s, string t) { | |
vector<int> sCheck(26); | |
vector<int> tCheck(26); | |
for(int i = 0 ; i < s.length();++i){ | |
sCheck[s[i] - 'a']++; | |
} | |
for(int i = 0 ; i < t.length();++i){ | |
tCheck[t[i] - 'a']++; | |
} | |
bool isSame = true; | |
for(int i = 0 ; i < 26;++i){ | |
if(sCheck[i] != tCheck[i]){ | |
isSame = false; | |
break; | |
} | |
} | |
return isSame; | |
} | |
}; | |
int main() { | |
Solution sol; | |
cout << sol.isAnagram("anagram", "nagaram") << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment