Files
LeetCode-Go/leetcode/1047.Remove-All-Adjacent-Duplicates-In-String/1047. Remove All Adjacent Duplicates In String.go
2020-08-07 17:06:53 +08:00

14 lines
276 B
Go

package leetcode
func removeDuplicates1047(S string) string {
stack := []rune{}
for _, s := range S {
if len(stack) == 0 || len(stack) > 0 && stack[len(stack)-1] != s {
stack = append(stack, s)
} else {
stack = stack[:len(stack)-1]
}
}
return string(stack)
}