From 1a884fa385e7a07bccec58e22a879361dcc6031f Mon Sep 17 00:00:00 2001 From: ductnn Date: Sat, 6 Apr 2024 00:11:08 +0700 Subject: [PATCH] add sol --- leetcode/1544.MakeTheStringGreat/sol.go | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 leetcode/1544.MakeTheStringGreat/sol.go 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