<filename>800-899/859.py
class Solution:
    def buddyStrings(self, s: str, goal: str) -> bool:
        if len(s) != len(goal):
            return False
        swapIndex = []
        isRepeat = False
        di = defaultdict(list)
        for i in range(len(s)):
            if s[i] == goal[i]:
                di[s[i]].append(i)
                if len(di[s[i]]) >= 2:
                    isRepeat = True
            else:
                swapIndex.append(i)
        return len(swapIndex) == 2 and s[swapIndex[0]] == goal[swapIndex[1]] and s[swapIndex[1]] == goal[swapIndex[0]] or (isRepeat and len(swapIndex) == 0)

<filename>800-899/859.py
class Solution:
    def buddyStrings(self, s: str, goal: str) -> bool:
        if len(s) != len(goal):
            return False
        swapIndex = []
        isRepeat = False
        di = defaultdict(list)
        for i in range(len(s)):
            if s[i] == goal[i]:
                di[s[i]].append(i)
                if len(di[s[i]]) >= 2:
                    isRepeat = True
            else:
                swapIndex.append(i)
        return len(swapIndex) == 2 and s[swapIndex[0]] == goal[swapIndex[1]] and s[swapIndex[1]] == goal[swapIndex[0]] or (isRepeat and len(swapIndex) == 0)
