Last active
February 13, 2022 22:56
-
-
Save CollinShoop/c831d933326ffb0846b6c38cd436b5ab to your computer and use it in GitHub Desktop.
Cracking the Coding Interview: URLIfy (solution)
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
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