We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 70bd064 commit a438373Copy full SHA for a438373
l33tcode/buddy-strings.py
@@ -0,0 +1,31 @@
1
+class Solution:
2
+ def buddyStrings(self, A: str, B: str) -> bool:
3
+ if len(A) != len(B):
4
+ return False
5
+
6
+ first, second = -1, -1
7
+ replacements = 0
8
+ pos = 0
9
10
+ while pos < len(A):
11
+ if A[pos] != B[pos]:
12
+ replacements += 1
13
14
+ if replacements > 2:
15
16
17
+ first, second = second, pos
18
19
+ pos += 1
20
21
22
23
+ elif replacements == 2:
24
+ if (A[first], A[second]) != (B[second], B[first]):
25
26
+ elif replacements == 1:
27
28
+ else:
29
+ return len(set(A)) != len(A)
30
31
+ return True
0 commit comments