1433.cpp (520B)
1 class Solution { 2 public: 3 bool checkIfCanBreak(const string &s1, const string &s2) const { 4 int vec[27] = {0}; 5 6 for (int i = 0; i < s1.size(); i++) { 7 vec[s1[i] & 0x1F]++; 8 vec[s2[i] & 0x1F]--; 9 } 10 11 bool b1 = false, b2 = false; 12 for (int i = 1, total = 0; i <= 26; i++) { 13 total += vec[i]; 14 if (total > 0) b1 = true; 15 if (total < 0) b2 = true; 16 if (b1 && b2) return false; 17 } 18 return true; 19 } 20 };