Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Apr 5, 2024
1 parent d721b07 commit 1a884fa
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions leetcode/1544.MakeTheStringGreat/sol.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// https://leetcode.com/problems/make-the-string-great

package main

import (
"fmt"
)

func makeGood(s string) string {
stk := []rune{}
for _, c := range s {
if len(stk) == 0 || abs(int(stk[len(stk)-1]-c)) != 32 {
stk = append(stk, c)
} else {
stk = stk[:len(stk)-1]
}
}
return string(stk)
}

func abs(x int) int {
if x < 0 {
return -x
}
return x
}

func main() {
s := "leEeetcode"

fmt.Println(makeGood(s))
}

0 comments on commit 1a884fa

Please sign in to comment.