Skip to content

Instantly share code, notes, and snippets.

@parcar
Last active August 20, 2019 19:22
Show Gist options
  • Select an option

  • Save parcar/0f9ab27e9bf889641e6c825d7716ba4f to your computer and use it in GitHub Desktop.

Select an option

Save parcar/0f9ab27e9bf889641e6c825d7716ba4f to your computer and use it in GitHub Desktop.
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
@parcar
Copy link
Author

parcar commented Aug 20, 2019

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