File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change 1
1
class Solution {
2
2
public boolean arrayStringsAreEqual (String [] word1 , String [] word2 ) {
3
- return Arrays .stream (word1 ).reduce ((a , b ) -> a + b )
4
- .equals (Arrays .stream (word2 ).reduce ((a , b ) -> a + b ));
3
+ int wordIdxOne = 0 ;
4
+ int wordIdxTwo = 0 ;
5
+ int idxOne = 0 ;
6
+ int idxTwo = 0 ;
7
+ while (wordIdxOne < word1 .length && wordIdxTwo < word2 .length ) {
8
+ if (idxOne == word1 [wordIdxOne ].length () || idxTwo == word2 [wordIdxTwo ].length ()) {
9
+ if (idxOne == word1 [wordIdxOne ].length ()) {
10
+ wordIdxOne ++;
11
+ idxOne = 0 ;
12
+ }
13
+ if (idxTwo == word2 [wordIdxTwo ].length ()) {
14
+ wordIdxTwo ++;
15
+ idxTwo = 0 ;
16
+ }
17
+ } else {
18
+ if (word1 [wordIdxOne ].charAt (idxOne ) != word2 [wordIdxTwo ].charAt (idxTwo )) {
19
+ return false ;
20
+ }
21
+ idxOne ++;
22
+ idxTwo ++;
23
+ }
24
+ }
25
+ return wordIdxOne == word1 .length && wordIdxTwo == word2 .length ;
5
26
}
6
27
}
You can’t perform that action at this time.
0 commit comments