Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ZhouYang1993/0f7972b6ce60e48571b58eadae8ff4a0 to your computer and use it in GitHub Desktop.
Save ZhouYang1993/0f7972b6ce60e48571b58eadae8ff4a0 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