Created
May 8, 2020 01:25
-
-
Save ZhouYang1993/0901463c5b9338c97141e2c6cce3bfc1 to your computer and use it in GitHub Desktop.
Algorithms for Interview 1: Stack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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