Skip to content

Commit e6daec3

Browse files
solves check if two strings are equivaent
1 parent 9e85ccc commit e6daec3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@
410410
| 1646 | [Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array) | [![Java](assets/java.png)](src/GetMaximumInGeneratedArray.java) | |
411411
| 1652 | [Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb) | [![Java](assets/java.png)](src/DefuseTheBomb.java) | |
412412
| 1656 | [Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream) | [![Java](assets/java.png)](src/DesignAnOrderedStream.java) | |
413-
| 1662 | [Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent) | | |
413+
| 1662 | [Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent) | [![Java](assets/java.png)](src/CheckIfTwoStringArraysAreEquivalent.java) | |
414414
| 1668 | [Maximum Repeating Substring](https://leetcode.com/problems/maximum-repeating-substring) | | |
415415
| 1672 | [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth) | | |
416416
| 1678 | [Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation) | | |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class CheckIfTwoStringArraysAreEquivalent {
2+
public boolean arrayStringsAreEqual(String[] word1, String[] word2) {
3+
for (int w1 = 0, w2 = 0, i = 0, j = 0 ; w1 < word1.length && w2 < word2.length ; ) {
4+
if (word1[w1].charAt(i) != word2[w2].charAt(j)) return false;
5+
if (i == word1[w1].length() - 1) {
6+
w1++;
7+
i = 0;
8+
} else {
9+
i++;
10+
}
11+
if (j == word2[w2].length() - 1) {
12+
w2++;
13+
j = 0;
14+
} else {
15+
j++;
16+
}
17+
if (w1 == word1.length && w2 == word2.length) return true;
18+
}
19+
return false;
20+
}
21+
}

0 commit comments

Comments
 (0)