Given two strings A and B of lowercase letters, return true if and only if we can swap two letters in A so that the result equals B.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Input: A = "ab", B = "ba" Output: true
Input: A = "ab", B = "ab" Output: false
Input: A = "aa", B = "aa" Output: true
Input: A = "aaaaaaabc", B = "aaaaaaacb" Output: true
Input: A = "", B = "aa" Output: false
Solution
The first method in my mind is to iterate different pair in String A and then exchange, and to see if it equals to B. Of course, this approach would be TLE, due to the time complexity is O(n^2). So, when I look the test case carefully, especially ths test case ofA: aa, B: aa. So, we have to compare to see if A and B equals.