Remove Adjacent Duplicates
Sat May 13 2023 11:25:56 GMT+0000 (Coordinated Universal Time)
Saved by
@Souvikdas
#not working
def removeDuplicates(self, s: str) -> str:
lis=[""]
for i in s:
if i not in lis:
lis.append(i)
elif i in lis:
lis.remove(i)
return ''.join(lis)
#working
def removeDuplicates(self, s: str) -> str:
stack = [""]
for c in s:
if stack[-1] == c:
stack.pop()
else:
stack.append(c)
return ''.join(stack)
content_copyCOPY
Comments