-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution3324.go
34 lines (27 loc) · 881 Bytes
/
solution3324.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package solution3324
// ============================================================================
// 3324. Find the Sequence of Strings Appeared on the Screen
// URL: https://leetcode.com/problems/find-the-sequence-of-strings-appeared-on-the-screen/
// ============================================================================
/*
goos: linux
goarch: amd64
pkg: GoLeetCode/solutions/3324
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
Benchmark_stringSequence
Benchmark_stringSequence-24 2483098 420.8 ns/op 498 B/op 17 allocs/op
PASS
*/
func stringSequence(target string) []string {
sequence := []string{""}
var n int
var prefix string
for _, ch := range target {
n = int(ch-'a') + 1
prefix = sequence[len(sequence)-1]
for i := 0; i < n; i++ {
sequence = append(sequence, prefix+string(rune(i+'a')))
}
}
return sequence[1:]
}