Minimum Swaps to Make Strings Equal LeetCode solution in Rust
1impl Solution {2pub fn minimum_swap(s1: String, s2: String) -> i32 {3let mut x1 = 0;4let mut y1 = 0;5for (c1, c2) in s1.chars().zip(s2.chars()) {6if c1 == 'x' && c2 == 'y' {7x1 += 1;8} else if c1 == 'y' && c2 == 'x' {9y1 += 1;10}11}12let mut ans = 0;13if x1 % 2 == 1 && y1 % 2 == 1 {14ans += 2;15x1 -= 1;16y1 -= 1;17}18ans += x1 / 2 + y1 / 2;19if x1 % 2 == 1 || y1 % 2 == 1 {20return -1;21}22ans23}24}