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

Commit 11b8949

Browse files
committed
1081 added
1 parent 4f61d7f commit 11b8949

File tree

5 files changed

+96
-1
lines changed

5 files changed

+96
-1
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
"leetcode",
122122
"len",
123123
"length",
124+
"letcod",
124125
"lexicographicaly",
125126
"lleeelee",
126127
"longest",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# [1081. Smallest Subsequence of Distinct Characters](https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/)
2+
3+
Return the lexicographically smallest subsequence of text that contains all the distinct characters of text exactly once.
4+
5+
Example 1:
6+
7+
```text
8+
Input: "cdadabcc"
9+
Output: "adbc"
10+
```
11+
12+
Example 2:
13+
14+
```text
15+
Input: "abcd"
16+
Output: "abcd"
17+
```
18+
19+
Example 3:
20+
21+
```text
22+
Input: "ecbacba"
23+
Output: "eacb"
24+
```
25+
26+
Example 4:
27+
28+
```text
29+
Input: "leetcode"
30+
Output: "letcod"
31+
```
32+
33+
Note:
34+
35+
1. `1 <= text.length <= 1000`
36+
1. `text consists of lowercase English letters.`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package problem1081
2+
3+
func smallestSubsequence(text string) string {
4+
5+
return ""
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package problem1081
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
// tcs is testcase slice
10+
var tcs = []struct {
11+
text string
12+
ans string
13+
}{
14+
15+
{
16+
"cdadabcc",
17+
"adbc",
18+
},
19+
20+
{
21+
"abcd",
22+
"abcd",
23+
},
24+
25+
{
26+
"ecbacba",
27+
"eacb",
28+
},
29+
30+
{
31+
"leetcode",
32+
"letcod",
33+
},
34+
35+
// 可以有多个 testcase
36+
}
37+
38+
func Test_smallestSubsequence(t *testing.T) {
39+
ast := assert.New(t)
40+
41+
for _, tc := range tcs {
42+
ast.Equal(tc.ans, smallestSubsequence(tc.text), "输入:%v", tc)
43+
}
44+
}
45+
46+
func Benchmark_smallestSubsequence(b *testing.B) {
47+
for i := 0; i < b.N; i++ {
48+
for _, tc := range tcs {
49+
smallestSubsequence(tc.text)
50+
}
51+
}
52+
}

leetcode.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Username": "aQuaYi",
33
"Ranking": 588,
4-
"Updated": "2019-07-14T16:50:27.400225559+08:00",
4+
"Updated": "2019-07-14T16:51:42.439165513+08:00",
55
"Record": {
66
"Easy": {
77
"Solved": 251,

0 commit comments

Comments
 (0)