Created
August 1, 2020 17:12
-
-
Save lbvf50mobile/20ac77a31e2990f8f8faf7e4a75a9cc0 to your computer and use it in GitHub Desktop.
Leetcode: 1047. Remove All Adjacent Duplicates In String.
This file contains 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
# 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