-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution2716.go
More file actions
32 lines (27 loc) · 757 Bytes
/
solution2716.go
File metadata and controls
32 lines (27 loc) · 757 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
package solution2716
// ============================================================================
// 2716. Minimize String Length
// URL: https://leetcode.com/problems/minimize-string-length/
// ============================================================================
/*
$ go test -bench=. -benchmem
goos: linux
goarch: amd64
pkg: GoLeetCode/solutions/2716---Minimize-String-Length
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
Benchmark_minimizeStringLength-24 362493421 3.318 ns/op 0 B/op 0 allocs/op
PASS
*/
func minimizedStringLength(s string) int {
freq := make([]int, 26)
ans := 0
idx := 0
for _, char := range s {
idx = int(char - 'a')
if freq[idx] == 0 {
ans++
}
freq[idx]++
}
return ans
}