[Interview] URLify:
--------------------------------------------------------------------------------------------------------------------------
Question:
--------------------------------------------------------------------------------------------------------------------------
Idea 1:
Start from the back and start replacing until the character is not ' ', and replace the characters in reverse order.
Solution 1:
URLify:
Write a method to replace all spaces in a string with
‘%20’, you may assume that the string has sufficient space at the
end to hold the additional characters.
Example
input: 'mr john smith '
output: 'mr%20john%20smith'
--------------------------------------------------------------------------------------------------------------------------
Idea 1:
Start from the back and start replacing until the character is not ' ', and replace the characters in reverse order.
Solution 1:
public class Solution{
public String replace(char[] str) {
boolean flag = false;
StringBuffer sb = new StringBuffer();
for (int i = str.length - 1; i >= 0; i--) {
if (str[i] != ' ')
flag = true;
if (flag == true) {
if (str[i] == ' ') {
sb.append('0');
sb.append('2');
sb.append('%');
} else {
sb.append(str[i]);
}
}
}
return sb.reverse().toString();
}
}
--------------------------------------------------------------------------------------------------------------------------
Video Explanation:
Play casino - No.1 for the Casino Guru
ReplyDeleteNo longer have the opportunity to go to worrione.com the titanium earrings casinos or read 출장샵 the reviews of the slots you love. https://deccasino.com/review/merit-casino/ But they're not always the same. Sometimes you have a new online https://sol.edu.kg/