Skip to content

Commit 1afaac8

Browse files
authored
Create 1662. Check If Two String Arrays are Equivalent
1 parent 2d4e1b5 commit 1afaac8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {
4+
int i = 0,j = 0,p_k1 = 0 , p_k2 = 0, p_i = 0 , p_j = 0;
5+
while(i<word1.size() and j < word2.size()){
6+
int k1 = 0 , k2 = 0;
7+
if(p_i == i) k1 = p_k1;
8+
if(p_j == j) k2 = p_k2;
9+
while(k1 < word1[i].size() and k2 < word2[j].size()){
10+
if(word1[i][k1] != word2[j][k2]) return false;
11+
k1++;
12+
k2++;
13+
}
14+
p_i = i;
15+
p_j = j;
16+
p_k1 = k1;
17+
p_k2 = k2;
18+
if(k1>=word1[i].size()) i++;
19+
if(k2>=word2[j].size()) j++;
20+
}
21+
if(i<word1.size() or j < word2.size()) return false;
22+
return true;
23+
}
24+
};

0 commit comments

Comments
 (0)