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 8c535ce

Browse files
author
Sandy
authored
Merge pull request #175 from openset/develop
Add: Repeated Substring Pattern
2 parents 332d334 + 2d929ee commit 8c535ce

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
package repeated_substring_pattern
2+
3+
import "strings"
4+
5+
func repeatedSubstringPattern(s string) bool {
6+
return strings.Contains((s + s)[1:2*len(s)-1], s)
7+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,54 @@
11
package repeated_substring_pattern
2+
3+
import "testing"
4+
5+
type caseType struct {
6+
input string
7+
expected bool
8+
}
9+
10+
func TestRepeatedSubstringPattern(t *testing.T) {
11+
tests := [...]caseType{
12+
{
13+
input: "a",
14+
expected: false,
15+
},
16+
{
17+
input: "abab",
18+
expected: true,
19+
},
20+
{
21+
input: "aba",
22+
expected: false,
23+
},
24+
{
25+
input: "abaaba",
26+
expected: true,
27+
},
28+
{
29+
input: "abcabcabcabc",
30+
expected: true,
31+
},
32+
{
33+
input: "abbaabbaabba",
34+
expected: true,
35+
},
36+
{
37+
input: "abcabcabcdabcabcabcdabcabcabcd",
38+
expected: true,
39+
},
40+
{
41+
input: "abaabaabac",
42+
expected: false,
43+
}, {
44+
input: "babbabbabbabbab",
45+
expected: true,
46+
},
47+
}
48+
for _, tc := range tests {
49+
output := repeatedSubstringPattern(tc.input)
50+
if output != tc.expected {
51+
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
52+
}
53+
}
54+
}

0 commit comments

Comments
(0)

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