bumpsoo 2025-02-05 23:35:39 +09:00
parent d0df9b92ca
commit c3e77d1121

View file

@ -0,0 +1,21 @@
# https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal
from typing import Optional
class Solution:
def areAlmostEqual(self, s1: str, s2: str) -> bool:
first: Optional[int] = None
second: Optional[int] = None
for i in range(len(s1)):
if s1[i] == s2[i]:
continue
if first is not None:
if second is not None:
return False
if s1[first] != s2[i] or s1[i] != s2[first]:
return False
second = i
else:
first = i
return not ((first is None) ^ (second is None))