1790. Check if One String Swap Can Make Strings Equal (Easy) - TengnanYao/daily_leetcode GitHub Wiki
class Solution(object):
def areAlmostEqual(self, s1, s2):
"""
:type s1: str
:type s2: str
:rtype: bool
"""
count = 0
temp = []
for i in range(len(s1)):
if s1[i] != s2[i]:
count += 1
if not temp:
temp = [s1[i], s2[i]]
else:
if s1[i] != temp[1] or s2[i] != temp[0]:
return False
return count == 0 or count == 2