go: add «1653. Minimum Deletions to Make String Balanced»
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
70c75e587a
commit
95c58e0ea3
1 changed files with 17 additions and 0 deletions
17
go/minimum-deletions-to-make-string-balanced.go
Normal file
17
go/minimum-deletions-to-make-string-balanced.go
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
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)]
|
||||||
|
}
|
Loading…
Reference in a new issue