-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution3304.go
More file actions
38 lines (30 loc) · 910 Bytes
/
solution3304.go
File metadata and controls
38 lines (30 loc) · 910 Bytes
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
35
36
37
38
package solution3304
// ============================================================================
// 3304. Find the K-th Character in String Game I
// URL: https://leetcode.com/problems/find-the-k-th-character-in-string-game-i/
// ============================================================================
/*
goos: linux
goarch: amd64
pkg: GoLeetCode/solutions/3304---Find-the-K-th-Character-in-String-Game-I
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
Benchmark_kthCharacter
Benchmark_kthCharacter-24 34771824 38.08 ns/op 8 B/op 3 allocs/op
PASS
*/
func kthCharacter(k int) byte {
output := make([]byte, 0, 501)
output = append(output, 'a')
for i := 0; i < k; i++ {
s := make([]byte, len(output))
copy(s, output)
for j := 0; j < len(s); j++ {
s[j]++
}
output = append(output, s...)
if len(output) > k {
break
}
}
return byte(output[k-1])
}