Buddy Strings

Title: Buddy Strings Source: leetcode.com

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:

Input: A = “ab”, B = “ba”
Output: true

Example 2:

Input: A = “ab”, B = “ab”
Output: false

Example 3:

Input: A = “aaabcccd”, B = “aaadcccb”
Output: true

Python solution

Buddy Strings
Rate this post

Leave a Reply