Skip to content

Commit 9727a94

Browse files
authored
Create .check-if-two-string-arrays-are-equivalent.py
1 parent 411ec2b commit 9727a94

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Time: O(n), n is the total length of word1 and word2
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def arrayStringsAreEqual(self, word1, word2):
6+
"""
7+
:type word1: List[str]
8+
:type word2: List[str]
9+
:rtype: bool
10+
"""
11+
idx1 = idx2 = arr_idx1 = arr_idx2 = 0
12+
while arr_idx1 < len(word1) and arr_idx2 < len(word2):
13+
if word1[arr_idx1][idx1] != word2[arr_idx2][idx2]:
14+
break
15+
idx1 += 1
16+
if idx1 == len(word1[arr_idx1]):
17+
idx1 = 0
18+
arr_idx1 += 1
19+
idx2 += 1
20+
if idx2 == len(word2[arr_idx2]):
21+
idx2 = 0
22+
arr_idx2 += 1
23+
return arr_idx1 == len(word1) and arr_idx2 == len(word2)

0 commit comments

Comments
 (0)