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

Commit 28e69d8

Browse files
committed
1081 done
1 parent c95a244 commit 28e69d8

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Algorithms/1081.smallest-subsequence-of-distinct-characters/smallest-subsequence-of-distinct-characters.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ package problem1081
22

33
import "strings"
44

5-
func smallestSubsequence(text string) string {
6-
n := len(text)
5+
func smallestSubsequence(S string) string {
6+
n := len(S)
77

88
last := [26]int{}
9-
for i, b := range text {
10-
last[b-'a'] = i
9+
for i, c := range S {
10+
last[c-'a'] = i
1111
}
1212

1313
stack, top := make([]int, n), -1
1414
hasSeen := [26]bool{}
1515
for i := 0; i < n; i++ {
16-
c := int(text[i] - 'a')
16+
c := int(S[i] - 'a')
1717
if hasSeen[c] {
1818
continue
1919
}
@@ -31,8 +31,9 @@ func smallestSubsequence(text string) string {
3131

3232
var sb strings.Builder
3333
for i := 0; i <= top; i++ {
34-
c := byte(stack[i] + 'a')
35-
sb.WriteByte(c)
34+
b := byte(stack[i] + 'a')
35+
sb.WriteByte(b)
3636
}
37+
3738
return sb.String()
3839
}

0 commit comments

Comments
 (0)