Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save CollinShoop/c831d933326ffb0846b6c38cd436b5ab to your computer and use it in GitHub Desktop.
Save CollinShoop/c831d933326ffb0846b6c38cd436b5ab to your computer and use it in GitHub Desktop.
Cracking the Coding Interview: URLIfy (solution)
func URLify(input []rune, l int) {
i := len(input)-1 // insert pointer, start as the last index of the input array
l-- // reading pointer, start at the end of the input string
for l >= 0 {
if input[l] == ' ' {
input[i-2] = '%'
input[i-1] = '2'
input[i] = '0'
i -= 3
} else {
input[i] = input[l]
i--
}
l--
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment