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

Commit 8eb792f

Browse files
committed
1081
1 parent 4672cea commit 8eb792f

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed
Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,44 @@
11
package problem1081
22

3-
import (
4-
"sort"
5-
"strings"
6-
)
3+
import "strings"
74

85
func smallestSubsequence(text string) string {
96
rec := make([][]int, 26)
7+
count := 0
108
for i, b := range text {
119
c := b - 'a'
1210
rec[c] = append(rec[c], i)
11+
if len(rec[c]) == 1 {
12+
count++
13+
}
1314
}
1415

15-
letters := make([]*letter, 0, 26)
16-
for i := 0; i < 26; i++ {
17-
if len(rec[i]) == 0 {
18-
continue
16+
flag := -1
17+
beforeAll := func() bool {
18+
ok := true
19+
for i := 0; i < 26 && ok; i++ {
20+
if len(rec[i]) == 0 {
21+
continue
22+
}
23+
1924
}
20-
letters = append(letters, &letter{
21-
char: byte(i + 'a'),
22-
indexs: rec[i],
23-
})
25+
return ok
2426
}
2527

26-
sort.Slice(letters, func(i int, j int) bool {
27-
return isLess(letters[i], letters[j])
28-
})
29-
3028
var sb strings.Builder
31-
for _, l := range letters {
32-
sb.WriteByte(l.char)
29+
for i := 0; i < count; i++ {
30+
for j := 0; j < 26; j++ {
31+
if len(rec[i]) == 0 {
32+
continue
33+
}
34+
j := 0
35+
for j < len(rec[i]) && rec[i][j] < flag {
36+
j++
37+
}
38+
index := rec[i][0]
39+
}
40+
3341
}
3442

3543
return sb.String()
3644
}
37-
38-
type letter struct {
39-
char byte
40-
indexs []int
41-
}
42-
43-
func isLess(a, b *letter) bool {
44-
if a.indexs[0] < b.indexs[len(b.indexs)-1] &&
45-
b.indexs[0] < a.indexs[len(a.indexs)-1] {
46-
return a.char < b.char
47-
}
48-
return false
49-
}

0 commit comments

Comments
 (0)