File tree Expand file tree Collapse file tree 3 files changed +48
-2
lines changed Expand file tree Collapse file tree 3 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,22 @@ class Solution:
4141<!-- 这里可写当前语言的特殊实现逻辑 -->
4242
4343``` java
44-
44+ class Solution {
45+ public String replaceSpaces (String S , int length ) {
46+ char [] c = S . toCharArray();
47+ int j = c. length;
48+ for (int i = length - 1 ; i >= 0 ; i-- ) {
49+ if (c[i] == ' ' ) {
50+ c[-- j] = ' 0' ;
51+ c[-- j] = ' 2' ;
52+ c[-- j] = ' %' ;
53+ } else {
54+ c[-- j] = c[i];
55+ }
56+ }
57+ return new String (c, j, c. length - j);
58+ }
59+ }
4560```
4661
4762### ...
Original file line number Diff line number Diff line change @@ -67,7 +67,22 @@ class Solution:
6767### Java
6868
6969``` java
70-
70+ class Solution {
71+ public String replaceSpaces (String S , int length ) {
72+ char [] c = S . toCharArray();
73+ int j = c. length;
74+ for (int i = length - 1 ; i >= 0 ; i-- ) {
75+ if (c[i] == ' ' ) {
76+ c[-- j] = ' 0' ;
77+ c[-- j] = ' 2' ;
78+ c[-- j] = ' %' ;
79+ } else {
80+ c[-- j] = c[i];
81+ }
82+ }
83+ return new String (c, j, c. length - j);
84+ }
85+ }
7186```
7287
7388### ...
Original file line number Diff line number Diff line change 1+ class Solution {
2+ public String replaceSpaces (String S , int length ) {
3+ char [] c = S .toCharArray ();
4+ int j = c .length ;
5+ for (int i = length - 1 ; i >= 0 ; i --) {
6+ if (c [i ] == ' ' ) {
7+ c [--j ] = '0' ;
8+ c [--j ] = '2' ;
9+ c [--j ] = '%' ;
10+ } else {
11+ c [--j ] = c [i ];
12+ }
13+ }
14+ return new String (c , j , c .length - j );
15+ }
16+ }
You can’t perform that action at this time.
0 commit comments