Created
April 6, 2018 20:50
-
-
Save bparanj/0cb12d67b7e9e795d7636d1d5c0d2584 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_white_spaces(string) | |
if (!string || string.size == 0) | |
return | |
end | |
read_index = 0 | |
write_index = 0 | |
while (read_index < string.length) | |
if (string[read_index] != ' ' && string[read_index] != '\t') | |
string[write_index] = string[read_index] | |
write_index += 1 | |
end | |
read_index += 1 | |
end | |
string[0, write_index] | |
end | |
data = ' All greek to me. ' | |
p remove_white_spaces(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Time: O(n)
Space: O(1)