Minimum Swaps to Make Strings Equal LeetCode solution in Python
1class Solution:2def minimumSwap(self, s1: str, s2: str) -> int:3h = defaultdict(int)4count = 0 # variable to keep track of the number of mismatches; it is impossible to make strings equal if count is odd5for i in range(len(s1)):6if s1[i] != s2[i]:7count += 18h[s1[i]] += 19if count % 2 != 0:10return -111res, a, b = 0, h["x"], h["y"]12res += a // 2 + b // 213if a % 2 == 0:14return res15return res + 2