[InterviewBit] Self Permutation

Self Permutation

  • Time :
  • Space :
1
2
3
4
5
6
7
8
int Solution::permuteStrings(string A, string B) {
if(A.length() != B.length()) return 0;
unordered_map<char, int> freq;
for(auto a : A) freq[a]++;
for(auto b : B) if(--freq[b] == 0) freq.erase(b);
return freq.empty();
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/11/16/PS/interviewbit/self-permutation/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.