-
-
Save goctave/2417969 to your computer and use it in GitHub Desktop.
CareerCup_1.4@1point3acres
This file contains hidden or 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 <string> | |
using namespace std; | |
bool is_anagram(const string &str1, const string &str2) | |
{ | |
if(str1.size() != str2.size()) | |
return false; | |
int cnt1[256] = {0}; | |
int cnt2[256] = {0}; | |
for(int i = 0; i < str1.size(); i++) | |
{ | |
cnt1[str1[i]]++; | |
cnt2[str2[i]]++; | |
} | |
for(int i = 0; i < 256; i++) | |
if(cnt1[i] != cnt2[i]) | |
return false; | |
return true; | |
} | |
int main() | |
{ | |
cout << is_anagram("ababab", "aaabbb") << endl; | |
cout << is_anagram("aaaaaa", "bbbbbb") << endl; | |
cout << is_anagram("abcdef", "aeabcd") << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment