Skip to content

Instantly share code, notes, and snippets.

@lelandjansen
Created September 13, 2016 21:48
Show Gist options
  • Save lelandjansen/539f4716bf88aa36cabdf1a97c905c8b to your computer and use it in GitHub Desktop.
Save lelandjansen/539f4716bf88aa36cabdf1a97c905c8b to your computer and use it in GitHub Desktop.
Determine if one string is a permutation of another
#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