go: add «1358. Number of Substrings Containing All Three Characters»

URL:	https://leetcode.com/problems/number-of-substrings-containing-all-three-characters/
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2025-03-11 09:10:02 +01:00
parent 3f4a94d02a
commit 2e9d570eb7
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -0,0 +1,15 @@
package main
import "slices"
func numberOfSubstrings(s string) int {
total := 0
lastPos := []int{-1, -1, -1}
for i, c := range s {
lastPos[c-'a'] = i
total += 1 + slices.Min(lastPos)
}
return total
}