-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path8. Check If Two String Arrays are Equivalent
More file actions
46 lines (36 loc) · 1.13 KB
/
8. Check If Two String Arrays are Equivalent
File metadata and controls
46 lines (36 loc) · 1.13 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class Solution {
public boolean arrayStringsAreEqual(String[] word1, String[] word2) {
String s1=makeString(word1);
String s2=makeString(word2);
return s1.equals(s2);
}
String makeString(String[] word){
StringBuilder sb=new StringBuilder();
for(String s:word){
sb.append(s);
}
return sb.toString();
}
}
class Solution {
public boolean arrayStringsAreEqual(String[] word1, String[] word2) {
int arrindex1=0,arrindex2=0;
int id1=0,id2=0;
while(arrindex1<word1.length && arrindex2<word2.length){
if(word1[arrindex1].charAt(id1) != word2[arrindex2].charAt(id2)){
return false;
}
id1++;
id2++;
if(id1==word1[arrindex1].length()){
id1=0;
arrindex1++;
}
if(id2==word2[arrindex2].length()){
id2=0;
arrindex2++;
}
}
return arrindex1==word1.length && arrindex2==word2.length;
}
}