Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 74ec5b6

Browse files
aQuaaQua
aQua
authored and
aQua
committed
521 added
1 parent d496b1d commit 74ec5b6

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# [521. Longest Uncommon Subsequence I](https://leetcode.com/problems/longest-uncommon-subsequence-i/)
2+
3+
## 题目
4+
5+
Given a group of two strings, you need to find the longest uncommon subsequence of this group of two strings.
6+
7+
The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other strings.
8+
9+
A subsequence is a sequence that can be derived from one sequence by deleting some characters without changing the order of the remaining elements. Trivially, any string is a subsequence of itself and an empty string is a subsequence of any string.
10+
11+
The input will be two strings, and the output needs to be the length of the longest uncommon subsequence. If the longest uncommon subsequence doesn't exist, return -1.
12+
13+
Example 1:
14+
15+
```text
16+
Input: "aba", "cdc"
17+
Output: 3
18+
Explanation: The longest uncommon subsequence is "aba" (or "cdc"), because "aba" is a subsequence of "aba", but not a subsequence of any other strings in the group of two strings.
19+
```
20+
21+
Note:
22+
23+
1. Both strings' lengths will not exceed 100.
24+
1. Only letters from a ~ z will appear in input strings.
25+
26+
## 解题思路
27+
28+
见程序注释
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package Problem0521
2+
3+
func findLUSlength(a string, b string) int {
4+
res := 3
5+
6+
return res
7+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package Problem0521
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
// tcs is testcase slice
11+
var tcs = []struct {
12+
a string
13+
b string
14+
ans int
15+
}{
16+
17+
{
18+
"aba",
19+
"cdc",
20+
3,
21+
},
22+
23+
// 可以有多个 testcase
24+
}
25+
26+
func Test_findLUSlength(t *testing.T) {
27+
ast := assert.New(t)
28+
29+
for _, tc := range tcs {
30+
fmt.Printf("~~%v~~\n", tc)
31+
ast.Equal(tc.ans, findLUSlength(tc.a, tc.b), "输入:%v", tc)
32+
}
33+
}
34+
35+
func Benchmark_findLUSlength(b *testing.B) {
36+
for i := 0; i < b.N; i++ {
37+
for _, tc := range tcs {
38+
findLUSlength(tc.a, tc.b)
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)