Check if One String Swap Can Make Strings Equal LeetCode solution in Python

1
# Runtime: 36 ms (Top 83.5%) | Memory: 16.25 MB (Top 70.5%)
2

3

4
class Solution:
5
def areAlmostEqual(self, s1: str, s2: str) -> bool:
6
diff = [[x, y] for x, y in zip(s1, s2) if x != y]
7
return not diff or len(diff) == 2 and diff[0][::-1] == diff[1]

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0