problems(java): add “1662. Check If Two String Arrays are Equivalent”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
8f34be49bb
commit
04eb72383c
1 changed files with 27 additions and 0 deletions
27
problems/java/check-if-two-string-arrays-are-equivalent.java
Normal file
27
problems/java/check-if-two-string-arrays-are-equivalent.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
class Solution {
|
||||
public boolean arrayStringsAreEqual(String[] word1, String[] word2) {
|
||||
int i = 0, ii = 0;
|
||||
int j = 0, jj = 0;
|
||||
|
||||
while (i < word1.length && j < word2.length) {
|
||||
if (word1[i].charAt(ii) != word2[j].charAt(jj)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
++ii;
|
||||
++jj;
|
||||
|
||||
if (ii >= word1[i].length()) {
|
||||
++i;
|
||||
ii = 0;
|
||||
}
|
||||
|
||||
if (jj >= word2[j].length()) {
|
||||
++j;
|
||||
jj = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return i == word1.length && j == word2.length && ii == 0 && jj == 0;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue