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 487b0d5

Browse files
author
Shuo
committed
A: Remove Palindromic Subsequences
1 parent 53f0c96 commit 487b0d5

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package problem1332
2+
3+
func removePalindromeSub(s string) int {
4+
if s == "" {
5+
return 0
6+
}
7+
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
8+
if s[i] != s[j] {
9+
return 2
10+
}
11+
}
12+
return 1
13+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package problem1332
2+
3+
import "testing"
4+
5+
type testType struct {
6+
in string
7+
want int
8+
}
9+
10+
func TestRemovePalindromeSub(t *testing.T) {
11+
tests := [...]testType{
12+
{
13+
in: "ababa",
14+
want: 1,
15+
},
16+
{
17+
in: "abb",
18+
want: 2,
19+
},
20+
{
21+
in: "baabb",
22+
want: 2,
23+
},
24+
{
25+
in: "",
26+
want: 0,
27+
},
28+
{
29+
in: "aaabbbaaabbb",
30+
want: 2,
31+
},
32+
}
33+
for _, tt := range tests {
34+
got := removePalindromeSub(tt.in)
35+
if got != tt.want {
36+
t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want)
37+
}
38+
}
39+
}

0 commit comments

Comments
(0)

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