leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1247.cpp (325B)
0 class Solution { 1 public: 2 int minimumSwap(const string &s1, const string &s2) { 3 int count[2] = {0}; 4 for (int i = 0; i < s1.size(); i++) 5 if (s1[i] != s2[i]) count[s1[i] & 1]++; 6 7 if ((count[0] + count[1]) % 2) return -1; 8 return (count[0] + 1) / 2 + (count[1] + 1) / 2; 9 } 10 };