Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Created August 1, 2020 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/20ac77a31e2990f8f8faf7e4a75a9cc0 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/20ac77a31e2990f8f8faf7e4a75a9cc0 to your computer and use it in GitHub Desktop.
Leetcode: 1047. Remove All Adjacent Duplicates In String.
# Leetcode: 1047. Remove All Adjacent Duplicates In String.
# https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/submissions/
# Runtime: 72 ms, faster than 93.10% of Ruby online submissions for Remove All Adjacent Duplicates In String.
# Memory Usage: 12.3 MB, less than 33.33% of Ruby online submissions for Remove All Adjacent Duplicates In String.
# @param {String} s
# @return {String}
def remove_duplicates(s)
a = s.gsub(/(.)\1/,'')
while(a != s)
s = a
a = s.gsub(/(.)\1/,'')
end
s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment