-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcheck-if-two-string-arrays-are-equivalent.py
More file actions
31 lines (24 loc) · 1.09 KB
/
Copy pathcheck-if-two-string-arrays-are-equivalent.py
File metadata and controls
31 lines (24 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from typing import List, Tuple
class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
pos1, index1 = 0, 0
pos2, index2 = 0, 0
def check_valid_pos(words: List[str], pos: int, index: int) -> bool:
return pos < len(words) and index < len(words[pos])
def get_next(words: List[str], pos: int, index: int) -> Tuple[int, int]:
if check_valid_pos(words, pos, index + 1):
return pos, index + 1
else:
return pos + 1, 0
while True:
if word1[pos1][index1] == word2[pos2][index2]:
pos1, index1 = get_next(word1, pos1, index1)
pos2, index2 = get_next(word2, pos2, index2)
else:
return False
if not check_valid_pos(word1, pos1, index1) or not check_valid_pos(word2, pos2, index2):
if not check_valid_pos(word1, pos1, index1) and not check_valid_pos(word2, pos2, index2):
break
else:
return False
return True