-
-
Save parcar/0f9ab27e9bf889641e6c825d7716ba4f to your computer and use it in GitHub Desktop.
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(object): | |
| def removeDuplicates(self, S): | |
| """ | |
| :type S: str | |
| :rtype: str | |
| """ | |
| if not len(S): | |
| return S | |
| ms = [] | |
| for i in S: | |
| if (len(ms) and i == ms[-1]): | |
| ms.pop() | |
| continue | |
| else: | |
| ms.append(i) | |
| return "".join(ms) | |
| #Stack String | |
| #A BBACA | |
| #AB BACA Top of stack == current letter so remove both | |
| #A ACA Again | |
| # CA | |
| #C A | |
| #CA | |
| #return stack |
Author
Author
Runtime: 68 ms, faster than 66.07% of Python online submissions for Remove All Adjacent Duplicates In String.
Memory Usage: 12.2 MB, less than 100.00% of Python online submissions for Remove All Adjacent Duplicates In String.
*Updated
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Runtime: 76 ms, faster than 53.80% of Python online submissions for Remove All Adjacent Duplicates In String.
Memory Usage: 12.3 MB, less than 100.00% of Python online submissions for Remove All Adjacent Duplicates In String.