leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1557.cpp (635B)


0 class Solution { 1 public: 2 bool closeStrings(const string &word1, const string &word2) { 3 if (word1.size() != word2.size()) return false; 4 const int n = word1.size(); 5 int w1[27] = {0}, w2[27] = {0}; 6 7 for (int i = 0; i < word1.size(); i++) { 8 w1[word1[i] & 0x1F]++; 9 w2[word2[i] & 0x1F]++; 10 } 11 12 for (int i = 1; i <= 26; i++) 13 if ((bool)w1[i] ^ (bool)w2[i]) return false; 14 15 sort(begin(w1), end(w1)); 16 sort(begin(w2), end(w2)); 17 18 for (int i = 0; i < 26; i++) 19 if (w1[i] != w2[i]) return false; 20 21 return true; 22 } 23 };