You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
315 B
Ruby

require 'Set'
# @param {String} text
# @return {String}
def remove_duplicate_characters(text)
visited_characters = Set.new
new_text = ''
text.each_char do |character|
new_text += character unless visited_characters.include? character
visited_characters << character
end
new_text
end