another way: def areAlmostEqual(self, s1: str, s2: str) -> bool: count, j = 0, 0 for i in range(len(s1)): if s1[i] != s2[i]: count += 1 if count == 1: j = i elif (count == 2 and s1[i] != s2[j] or s2[i] != s1[j]) or count > 2: return False return count != 1
@smartdragon25045 күн бұрын
this is similar to what i did , noice
@setkaung7295 күн бұрын
similar to mine,great
@araneuskyuro4 күн бұрын
Quick question, instead of checking len(indexes) == 0 would it not be better to return True initially itself on If s1 == s2: return True ? The iteration over the entire string feels a bit pointless in that case
@rhugvedbhojane43875 күн бұрын
I watch so much neetcode that my solutions are getting similar to his
@Douglascaina5 күн бұрын
great solution!
@Sammie_5 күн бұрын
feelsgood to beat neetcode by having slightly better memory usage while being on 100%.
@Deadmanstrolln5 күн бұрын
I really hate that they call this "string" swapping. At least for languages I'm familiar with, you're swapping chars of a string. Swapping strings makes it sound like there is some substring (of any length) that can be swapped with another substring (of any length) to make the 2 original strings equal
@Nishanth_S5 күн бұрын
+1
@dialgos75745 күн бұрын
That would be a really interesting and probably challenging exercise
@araneuskyuro4 күн бұрын
Lisan Al Gaib, I am sure this will be a daily problem soon
@jeehar16 күн бұрын
Nice sol man
@sandeepsalwan29115 күн бұрын
🔥
@alizu38035 күн бұрын
did the brute force in 40s things are going good
@UltiRequiem5 күн бұрын
I have not seen the video. My udea: Check for the diff, the diff must be exactly two.
@cordrust5 күн бұрын
they need to be the same different characters
@Tahsan147105 күн бұрын
test case 'aa' 'bb' has exactly two, but It can't be same by swapping.
@abdalla44255 күн бұрын
easy -> 50% acceptance rating >.< lmao we got baited