Skip to content

Commit d85d54d

Browse files
authored
Create 乔戈里.md
1 parent d263272 commit d85d54d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

2019.11.24/乔戈里.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
```

0 commit comments

Comments
 (0)