Github 同步地址: https://github.com/grandyang/leetcode/issues/1247 类似题目: Determine if Two Strings Are Close 参考资料: https://leetcode.com/problems/minimum-swaps-to-make-strings-equal/ https://leetcode.com/problems/minimum-swaps-to-make-strings-equal/discuss/419691/C%2B%2B-simple-solution...
You are given two stringss1ands2of equal length consisting of letters"x"and"y"only. Your task is to make these two strings equal to each other. You can swap any two characters that belong to different strings, which means: swaps1[i]ands2[j]. Return the minimum number of swaps required...
Can you solve this real interview question? Minimum Swaps to Make Strings Equal - You are given two strings s1 and s2 of equal length consisting of letters "x" and "y" only. Your task is to make these two strings equal to each other. You can swap any two
=021{22return-1;//if number of 'x' or 'y' is odd, we can not make s1 equals to s223}24//Cases to do 1 swap:25//"xx" => x1 / 2 => how many pairs of 'x' we have ?26//"yy" => y1 / 2 => how many pairs of 'y' we have ?27//28//Cases to do 2 swaps:29/...
Return the minimum number of swaps required to makes1ands2equal, or return-1if it is impossible to do so. Example 1: Input: s1 = "xx", s2 = "yy" Output: 1 Explanation: Swap s1[0] and s2[1], s1 = "yx", s2 = "yx". ...