File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ ```
2
+ import java.util.*;
3
+ public class Solution {
4
+ public String replaceSpace(StringBuffer str) {
5
+ String str1 = str.toString();
6
+ if(str1.equals(""))
7
+ return str1;
8
+ char [] strArray = str1.toCharArray();
9
+ int i =0;
10
+ int lengthSpace = 0;
11
+ while(i < strArray.length)
12
+ {
13
+ if(strArray[i] == ' ')
14
+ lengthSpace++;
15
+ i++;
16
+ }
17
+ int newStrLength = strArray.length + lengthSpace*2;
18
+ char [] newStr = new char[newStrLength];
19
+ int j = newStrLength-1;
20
+ i = strArray.length - 1;
21
+ while(i >= 0)
22
+ {
23
+ if(strArray[i] != ' ')
24
+ {
25
+ newStr[j--] = strArray[i--];
26
+ }else{
27
+ newStr[j--] = '0';
28
+ newStr[j--] = '2';
29
+ newStr[j--] = '%';
30
+ i--;
31
+ }
32
+ }
33
+ return new String(newStr);
34
+ }
35
+ }
36
+ ```
You can’t perform that action at this time.
0 commit comments