Buddy Strings
Given two strings s and goal, return true if you can swap two letters in s so the result is equal to goal; otherwise, return false.
Swapping letters is defined as taking two indices i and j (0-indexed) such that i != j and swapping the characters at s[i] and s[j].
Example 1
Input
s = "ab", goal = "ba"Output
trueYou can swap s[0] = 'a' and s[1] = 'b' to get "ba", which is equal to goal.
Example 2
Input
s = "ab", goal = "ab"Output
falseThe only letters you can swap are s[0] = 'a' and s[1] = 'b', which results in "ba" != goal.
Constraints
- 1 <= s.length, goal.length <= 2 * 10^4
- s and goal consist of lowercase letters.