2
https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal/4
Find the number of positions which are different.5
Now the strings can be made equal only if there are 06
different positions or 2 different positions and there are7
chars on those positions which when swaped will make the10
SC: O(1), At most 2 values are put in the diff_pos vector15
bool areAlmostEqual(string s1, string s2) {16
// find the number of diff positions18
for (int i = 0; i < s1.size(); i++) {19
if (s1[i] != s2[i]) diff_pos.emplace_back(i);20
// If there are more than 2 char positions that differ,21
// the single swap op cannot anyway make the two strings equal22
if (diff_pos.size() > 2) return false;24
// when the chars are exactly the same25
if (diff_pos.empty()) return true;26
// only one pair of diff positions, check if swapping makes them equal27
if (diff_pos.size() == 2) swap(s1[diff_pos[0]], s1[diff_pos[1]]);