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