1247.cpp (325B)
1 class Solution { 2 public: 3 int minimumSwap(const string &s1, const string &s2) { 4 int count[2] = {0}; 5 for (int i = 0; i < s1.size(); i++) 6 if (s1[i] != s2[i]) count[s1[i] & 1]++; 7 8 if ((count[0] + count[1]) % 2) return -1; 9 return (count[0] + 1) / 2 + (count[1] + 1) / 2; 10 } 11 };