Solved LeetCode program · 901 of 1,000
#1247 · Minimum Swaps to Make Strings Equal
Original English source
The first is "xx". The second is "yy". The leftovers is 0. The rightovers is 0.
For every spot from 0 to the last position of first.
The left is character spot of first. The right is character spot of second. If left is "x" and right is "y", add 1 to leftovers. If left is "y" and right is "x", add 1 to rightovers.
The mismatch is leftovers plus rightovers. If mismatch modulo 2 is 1, show -1.
If mismatch modulo 2 is 0.
The swaps is leftovers divided by 2 plus rightovers divided by 2 plus (leftovers modulo 2) times 2. Show swaps.
Expected stdout
1