Skip to content

Instantly share code, notes, and snippets.

@bparanj
Created April 6, 2018 20:50
Show Gist options
  • Save bparanj/0cb12d67b7e9e795d7636d1d5c0d2584 to your computer and use it in GitHub Desktop.
Save bparanj/0cb12d67b7e9e795d7636d1d5c0d2584 to your computer and use it in GitHub Desktop.
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)
@bparanj
Copy link
Author

bparanj commented Apr 6, 2018

Time: O(n)
Space: O(1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment