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:
parent
3f4a94d02a
commit
2e9d570eb7
1 changed files with 15 additions and 0 deletions
15
go/number-of-substrings-containing-all-three-characters.go
Normal file
15
go/number-of-substrings-containing-all-three-characters.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue