programming-examples/ruby/Algorithms/remove_duplicates.rb

17 lines
315 B
Ruby
Raw Normal View History

2019-11-15 12:59:38 +01:00
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