0859. Buddy Strings
https://leetcode.com/problems/buddy-strings
Description
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]
.
For example, swapping at indices
0
and2
in"abcd"
results in"cbad"
.
Example 1:
Example 2:
Example 3:
Example 4:
Constraints:
1 <= s.length, goal.length <= 2 * 104
s
andgoal
consist of lowercase letters.
ac
Last updated