File tree Expand file tree Collapse file tree 4 files changed +53
-4
lines changed
solution/1600-1699/1662.Check If Two String Arrays are Equivalent Expand file tree Collapse file tree 4 files changed +53
-4
lines changed Original file line number Diff line number Diff line change @@ -52,22 +52,39 @@ word2 表示的字符串为 "a" + "bc" -> "abc"
52
52
53
53
<!-- 这里可写通用的实现逻辑 -->
54
54
55
+ 字符串拼接,比较。
56
+
55
57
<!-- tabs:start -->
56
58
57
59
### ** Python3**
58
60
59
61
<!-- 这里可写当前语言的特殊实现逻辑 -->
60
62
61
63
``` 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
63
68
```
64
69
65
70
### ** Java**
66
71
67
72
<!-- 这里可写当前语言的特殊实现逻辑 -->
68
73
69
74
``` 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
+ }
71
88
```
72
89
73
90
### ** ...**
Original file line number Diff line number Diff line change @@ -51,13 +51,28 @@ The strings are the same, so return true.</pre>
51
51
### ** Python3**
52
52
53
53
``` 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
55
58
```
56
59
57
60
### ** Java**
58
61
59
62
``` 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
+ }
61
76
```
62
77
63
78
### ** ...**
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments