Skip to content

Instantly share code, notes, and snippets.

@bparanj
Created April 6, 2018 20:05
Show Gist options
  • Save bparanj/2c93118900ecb2fcdf4a24a58f8f18de to your computer and use it in GitHub Desktop.
Save bparanj/2c93118900ecb2fcdf4a24a58f8f18de to your computer and use it in GitHub Desktop.
require 'set'
def remove_duplicates(string)
hashset = Set.new
write_index = 0
read_index = 0
while (read_index < string.length)
unless hashset.include?(string[read_index])
hashset.add(string[read_index])
string[write_index] = string[read_index]
write_index += 1
end
read_index += 1
end
string[0, write_index]
end
p remove_duplicates('abbabcddbabcdeedebc')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment