diff --git a/leetcode/1544.MakeTheStringGreat/sol.go b/leetcode/1544.MakeTheStringGreat/sol.go new file mode 100644 index 0000000..b939f22 --- /dev/null +++ b/leetcode/1544.MakeTheStringGreat/sol.go @@ -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)) +} \ No newline at end of file