1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-19 17:56:55 +02:00
LeetCode/go/minimum-deletions-to-make-string-balanced.go

18 lines
227 B
Go
Raw Normal View History

package main
func minimumDeletions(s string) int {
dp := make([]int, len(s)+1)
bs := 0
for i, c := range s {
if c == 'b' {
dp[i+1] = dp[i]
bs++
} else {
dp[i+1] = min(dp[i]+1, bs)
}
}
return dp[len(s)]
}