leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1433.cpp (520B)
0 class Solution { 1 public: 2 bool checkIfCanBreak(const string &s1, const string &s2) const { 3 int vec[27] = {0}; 4 5 for (int i = 0; i < s1.size(); i++) { 6 vec[s1[i] & 0x1F]++; 7 vec[s2[i] & 0x1F]--; 8 } 9 10 bool b1 = false, b2 = false; 11 for (int i = 1, total = 0; i <= 26; i++) { 12 total += vec[i]; 13 if (total > 0) b1 = true; 14 if (total < 0) b2 = true; 15 if (b1 && b2) return false; 16 } 17 return true; 18 } 19 };