Created
September 13, 2016 21:48
-
-
Save lelandjansen/539f4716bf88aa36cabdf1a97c905c8b to your computer and use it in GitHub Desktop.
Determine if one string is a permutation of another
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 <string> | |
#include <map> | |
bool IsPermutation(std::string &a, std::string &b) { | |
std::map<char, std::pair<int, int>> char_map; | |
for (auto c : a) ++char_map[c].first; | |
for (auto c : b) ++char_map[c].second; | |
for (auto it : char_map) | |
if (it.second.first != it.second.second) return false; | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment