Skip to content

Commit 7a9f5b9

Browse files
committed
Time: 3 ms (7.87%) | Memory: 40.7 MB (28.67%) - LeetSync
1 parent 1fa16bd commit 7a9f5b9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public boolean arrayStringsAreEqual(String[] word1, String[] word2) {
3+
int p1 = 0, p2 = 0; // inner pointer
4+
int w1 = 0, w2 = 0; // outer pointer
5+
6+
while (w1 < word1.length && w2 < word2.length) {
7+
String curr1 = word1[w1], curr2 = word2[w2];
8+
9+
if (curr1.charAt(p1) != curr2.charAt(p2)) return false;
10+
11+
if (p1 < curr1.length() - 1) {
12+
p1++;
13+
} else {
14+
p1 = 0;
15+
w1++;
16+
}
17+
18+
if (p2 < curr2.length() - 1) {
19+
p2++;
20+
} else {
21+
p2 = 0;
22+
w2++;
23+
}
24+
}
25+
26+
return w1 == word1.length && w2 == word2.length;
27+
}
28+
}

0 commit comments

Comments
 (0)