Created
April 6, 2018 20:38
-
-
Save bparanj/f36b9ce1a0042f8588c972d65a33a21b to your computer and use it in GitHub Desktop.
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
def remove_duplicates(string) | |
write_index = 0 | |
for i in 0..string.length-1 | |
found = false | |
for j in 0..write_index-1 | |
if (string[i] == string[j]) | |
found = true | |
break | |
end | |
end | |
unless found | |
string[write_index] = string[i] | |
write_index += 1 | |
end | |
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