You are given two strings s1 and s2 of equal length. A string swap is an operation where you choose two indices in a string (not necessarily different) and swap the characters at these indices.
Return trueif it is possible to make both strings equal by performing at most one string swap on exactly one of the strings. Otherwise, return false.
classSolution:
defareAlmostEqual(s1: str, s2: str) -> bool:
first =-1 second =-1 diffCount =0for i in range(len(s1)):
if s1[i] != s2[i]:
diffCount +=1if first ==-1:
first = i
else:
second = i
if diffCount >2:
returnFalseif diffCount ==2and s1[first] == s2[second] and s1[second] == s2[first]:
returnTruereturn diffCount ==0