import"container/list"import"strings"funcremoveDuplicates(S string)string{
stack :=list.New()var b strings.Builder
for i:=0;i<len(S);i++{if stack.Len()>0{if stack.Back().Value.(byte)== S[i]{
stack.Remove(stack.Back())continue}}
stack.PushBack(S[i])}for{if e :=stack.Front(); e !=nil{
b.WriteByte(e.Value.(byte))
stack.Remove(e)}else{break}}return b.String()}
python版邻去重
classSolution:defremoveDuplicates(self, S:str)->str:
l =[]for v in S:iflen(l)>0:if l[len(l)-1]== v :
l.pop()continue
l.append(v)return"".join(l)
删除重复项使用golang双向链表重当栈import "container/list"import "strings"func removeDuplicates(S string) string { stack :=list.New() var b strings.Builder for i:=0;i<len(S);i++ { if stack.Len() > 0 { if stack.Back().Value.(b