Skip to content

Commit 23522f7

Browse files
author
Shuo
committed
A: Check If Two String Arrays are Equivalent
1 parent e1da124 commit 23522f7

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package problem1662
2+
3+
import "strings"
4+
5+
func arrayStringsAreEqual(word1 []string, word2 []string) bool {
6+
str1 := strings.Builder{}
7+
for _, s := range word1 {
8+
str1.WriteString(s)
9+
}
10+
str2 := strings.Builder{}
11+
for _, s := range word2 {
12+
str2.WriteString(s)
13+
}
14+
return str1.String() == str2.String()
15+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package problem1662
2+
3+
import "testing"
4+
5+
type testType struct {
6+
word1 []string
7+
word2 []string
8+
want bool
9+
}
10+
11+
func TestArrayStringsAreEqual(t *testing.T) {
12+
tests := [...]testType{
13+
{
14+
word1: []string{"ab", "c"},
15+
word2: []string{"a", "bc"},
16+
want: true,
17+
},
18+
{
19+
word1: []string{"a", "cb"},
20+
word2: []string{"ab", "c"},
21+
want: false,
22+
},
23+
{
24+
word1: []string{"abc", "d", "defg"},
25+
word2: []string{"abcddefg"},
26+
want: true,
27+
},
28+
}
29+
for _, tt := range tests {
30+
got := arrayStringsAreEqual(tt.word1, tt.word2)
31+
if got != tt.want {
32+
t.Fatalf("word1: %v, word2: %v, got: %v, want: %v", tt.word1, tt.word2, got, tt.want)
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)