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 6f5d6c6

Browse files
author
Sandy
authored
Merge pull request #110 from openset/develop
Add: groups_of_special_equivalent_strings
2 parents 919c709 + 5fd17dd commit 6f5d6c6

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
11
package groups_of_special_equivalent_strings
2+
3+
func numSpecialEquivGroups(A []string) int {
4+
m := make(map[[52]int]bool)
5+
for _, s := range A {
6+
var count [52]int
7+
for i, char := range s {
8+
count[int(char)-'a'+26*(i%2)]++
9+
}
10+
m[count] = true
11+
}
12+
return len(m)
13+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
11
package groups_of_special_equivalent_strings
2+
3+
import "testing"
4+
5+
type caseType struct {
6+
input []string
7+
expected int
8+
}
9+
10+
func TestNumSpecialEquivGroups(t *testing.T) {
11+
tests := [...]caseType{
12+
{
13+
input: []string{"a", "b", "c", "a", "c", "c"},
14+
expected: 3,
15+
},
16+
{
17+
input: []string{"aa", "bb", "ab", "ba"},
18+
expected: 4,
19+
},
20+
{
21+
input: []string{"abc", "acb", "bac", "bca", "cab", "cba"},
22+
expected: 3,
23+
},
24+
{
25+
input: []string{"abcd", "cdab", "adcb", "cbad"},
26+
expected: 1,
27+
},
28+
}
29+
for _, tc := range tests {
30+
output := numSpecialEquivGroups(tc.input)
31+
if output != tc.expected {
32+
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
33+
}
34+
}
35+
}

0 commit comments

Comments
(0)

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