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 dfd0838

Browse files
author
Openset
committed
Add: Longest Uncommon Subsequence I
1 parent 6c60840 commit dfd0838

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
11
package longest_uncommon_subsequence_i
2+
3+
func findLUSlength(a string, b string) int {
4+
if a == b {
5+
return -1
6+
}
7+
if len(a) > len(b) {
8+
return len(a)
9+
}
10+
return len(b)
11+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,40 @@
11
package longest_uncommon_subsequence_i
2+
3+
import "testing"
4+
5+
type caseType struct {
6+
a string
7+
b string
8+
expected int
9+
}
10+
11+
func TestFindLUSlength(t *testing.T) {
12+
tests := [...]caseType{
13+
{
14+
a: "aba",
15+
b: "cdc",
16+
expected: 3,
17+
},
18+
{
19+
a: "aba",
20+
b: "abcdef",
21+
expected: 6,
22+
},
23+
{
24+
a: "abcdef",
25+
b: "cdc",
26+
expected: 6,
27+
},
28+
{
29+
a: "abc",
30+
b: "abc",
31+
expected: -1,
32+
},
33+
}
34+
for _, tc := range tests {
35+
output := findLUSlength(tc.a, tc.b)
36+
if output != tc.expected {
37+
t.Fatalf("input: %v %v, output: %v, expected: %v", tc.a, tc.b, output, tc.expected)
38+
}
39+
}
40+
}

0 commit comments

Comments
(0)

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