Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
package repeated_substring_pattern

import "strings"

func repeatedSubstringPattern(s string) bool {
return strings.Contains((s + s)[1:2*len(s)-1], s)
}
Original file line number Diff line number Diff line change
@@ -1 +1,54 @@
package repeated_substring_pattern

import "testing"

type caseType struct {
input string
expected bool
}

func TestRepeatedSubstringPattern(t *testing.T) {
tests := [...]caseType{
{
input: "a",
expected: false,
},
{
input: "abab",
expected: true,
},
{
input: "aba",
expected: false,
},
{
input: "abaaba",
expected: true,
},
{
input: "abcabcabcabc",
expected: true,
},
{
input: "abbaabbaabba",
expected: true,
},
{
input: "abcabcabcdabcabcabcdabcabcabcd",
expected: true,
},
{
input: "abaabaabac",
expected: false,
}, {
input: "babbabbabbabbab",
expected: true,
},
}
for _, tc := range tests {
output := repeatedSubstringPattern(tc.input)
if output != tc.expected {
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
}
}
}