Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3287007

Browse files
author
openset
committed
Add: Rotate String
1 parent 9432088 commit 3287007

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
11
package rotate_string
2+
3+
import "strings"
4+
5+
func rotateString(A string, B string) bool {
6+
if len(A) != len(B) {
7+
return false
8+
}
9+
A = strings.Repeat(A, 2)
10+
return strings.Contains(A, B)
11+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
11
package rotate_string
2+
3+
import "testing"
4+
5+
type caseType struct {
6+
A string
7+
B string
8+
expected bool
9+
}
10+
11+
func TestRotateString(t *testing.T) {
12+
tests := [...]caseType{
13+
{
14+
A: "abcde",
15+
B: "cdeab",
16+
expected: true,
17+
},
18+
{
19+
A: "abcde",
20+
B: "abced",
21+
expected: false,
22+
},
23+
}
24+
for _, tc := range tests {
25+
output := rotateString(tc.A, tc.B)
26+
if output != tc.expected {
27+
t.Fatalf("input: %v %v, output: %v, expected: %v", tc.A, tc.B, output, tc.expected)
28+
}
29+
}
30+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /