Skip to content

Instantly share code, notes, and snippets.

@ZhouYang1993
Created May 8, 2020 01:25
Show Gist options
  • Save ZhouYang1993/0901463c5b9338c97141e2c6cce3bfc1 to your computer and use it in GitHub Desktop.
Save ZhouYang1993/0901463c5b9338c97141e2c6cce3bfc1 to your computer and use it in GitHub Desktop.
Algorithms for Interview 1: Stack
class Solution:
def removeDuplicates(self, S: str) -> str:
stack = []
for char in S:
if (not stack) or (stack[-1]!=char):
stack.append(char)
else:
while stack and stack[-1] == char:
stack.pop()
return ''.join(stack)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment