Skip to content

Commit 7d81350

Browse files
committed
feat: add solutions to lc problem: No.1662. Check If Two String Arrays
are Equivalent
1 parent 434ffdb commit 7d81350

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

solution/1600-1699/1662.Check If Two String Arrays are Equivalent/README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,39 @@ word2 表示的字符串为 "a" + "bc" -> "abc"
5252

5353
<!-- 这里可写通用的实现逻辑 -->
5454

55+
字符串拼接,比较。
56+
5557
<!-- tabs:start -->
5658

5759
### **Python3**
5860

5961
<!-- 这里可写当前语言的特殊实现逻辑 -->
6062

6163
```python
62-
64+
class Solution:
65+
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
66+
s1, s2 = ''.join(word1), ''.join(word2)
67+
return s1 == s2
6368
```
6469

6570
### **Java**
6671

6772
<!-- 这里可写当前语言的特殊实现逻辑 -->
6873

6974
```java
70-
75+
class Solution {
76+
public boolean arrayStringsAreEqual(String[] word1, String[] word2) {
77+
StringBuilder s1 = new StringBuilder();
78+
StringBuilder s2 = new StringBuilder();
79+
for (String word : word1) {
80+
s1.append(word);
81+
}
82+
for (String word : word2) {
83+
s2.append(word);
84+
}
85+
return Objects.equals(s1.toString(), s2.toString());
86+
}
87+
}
7188
```
7289

7390
### **...**

solution/1600-1699/1662.Check If Two String Arrays are Equivalent/README_EN.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,28 @@ The strings are the same, so return true.</pre>
5151
### **Python3**
5252

5353
```python
54-
54+
class Solution:
55+
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
56+
s1, s2 = ''.join(word1), ''.join(word2)
57+
return s1 == s2
5558
```
5659

5760
### **Java**
5861

5962
```java
60-
63+
class Solution {
64+
public boolean arrayStringsAreEqual(String[] word1, String[] word2) {
65+
StringBuilder s1 = new StringBuilder();
66+
StringBuilder s2 = new StringBuilder();
67+
for (String word : word1) {
68+
s1.append(word);
69+
}
70+
for (String word : word2) {
71+
s2.append(word);
72+
}
73+
return Objects.equals(s1.toString(), s2.toString());
74+
}
75+
}
6176
```
6277

6378
### **...**
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public boolean arrayStringsAreEqual(String[] word1, String[] word2) {
3+
StringBuilder s1 = new StringBuilder();
4+
StringBuilder s2 = new StringBuilder();
5+
for (String word : word1) {
6+
s1.append(word);
7+
}
8+
for (String word : word2) {
9+
s2.append(word);
10+
}
11+
return Objects.equals(s1.toString(), s2.toString());
12+
}
13+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Solution:
2+
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
3+
s1, s2 = ''.join(word1), ''.join(word2)
4+
return s1 == s2

0 commit comments

Comments
 (0)