Skip to content
This repository was archived by the owner on Sep 22, 2021. It is now read-only.

Commit 72f8973

Browse files
added a buddy strings implementation
1 parent 21fb652 commit 72f8973

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

LeetCode/0859_Buddy_String.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def buddyStrings(self, A: str, B: str) -> bool:
3+
indexes_to_swap = []
4+
for idx, string in enumerate(A):
5+
if string != B[idx]:
6+
indexes_to_swap.append(idx)
7+
if len(indexes_to_swap) > 2:
8+
return False
9+
10+
if len(indexes_to_swap) != 2:
11+
return false
12+
13+
return A[indexes_to_swap[0]] == B[indexes_to_swap[1]] and A[indexes_to_swap[1]] == B[indexes_to_swap[0]]

0 commit comments

Comments
 (0)