1
# Runtime: 54 ms (Top 48.33%) | Memory: 14.1 MB (Top 96.59%)3
from collections import Counter7
def buddyStrings(self, s: str, goal: str) -> bool:8
if len(s) != len(goal):10
diffCharactersCount = 011
diffCharactersInS = []12
diffCharactersInGoal = []13
for i in range(len(s)):15
diffCharactersCount += 116
diffCharactersInS.append(s[i])17
diffCharactersInGoal.append(goal[i])18
if diffCharactersCount == 2:19
# if there are only 2 different characters, then they should be swappable20
if (diffCharactersInS[0] == diffCharactersInGoal[1]) and (21
diffCharactersInS[1] == diffCharactersInGoal[0]25
elif diffCharactersCount == 0:26
# if there is atleast one repeating character in the string then its possible for swap28
for k, v in counts.items():31
# if different characters count is not 2 or 0, then it's not possible for the strings to be buddy strings