![]() |
VOOZH | about |
Given a string s, replace all the spaces in the string with '%20'.
Examples:
Input: s = "i love programming"
Output: i%20love%20programming
Explanation: The 2 spaces are replaced by '%20'Input: s = "ab cd"
Output: ab%20cd
The idea is to iterate through each character of the input string and build a new string (or result container). Whenever a space character is encountered, replace it with the string "%20", otherwise append the current character as it is.
Dry run for s = "g ee ks":
Traversal is complete, so the final result "g%20ee%20ks" is returned.
i%20love%20programming