Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fa61107

Browse files
Merge pull request doocs#265 from J-Cod3r/master
add string to url java solution
2 parents b48d193 + 614df8c commit fa61107

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

‎lcci/01.03.String to URL/README.md‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff 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
### ...

‎lcci/01.03.String to URL/README_EN.md‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff 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
### ...
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /