classSolution{public:// Similar to 859. Buddy StringsboolareAlmostEqual(strings1,strings2){vector<int>diffIndices;for(inti=0;i<s1.length();++i)if(s1[i]!=s2[i])diffIndices.push_back(i);returndiffIndices.empty()||(diffIndices.size()==2&&s1[diffIndices[0]]==s2[diffIndices[1]]&&s1[diffIndices[1]]==s2[diffIndices[0]]);}};
classSolution:# Similar to 859. Buddy StringsdefareAlmostEqual(self,s1:str,s2:str)->bool:diffIndices=[ifori,(a,b)inenumerate(zip(s1,s2))ifa!=b]returnnotdiffIndicesor(len(diffIndices)==2ands1[diffIndices[0]]==s2[diffIndices[1]]ands1[diffIndices[1]]==s2[diffIndices[0]])