Skip to content

add string to url java solution #265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lcci/01.03.String to URL/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,22 @@ class Solution:
<!-- 这里可写当前语言的特殊实现逻辑 -->

```java

class Solution {
public String replaceSpaces(String S, int length) {
char[] c = S.toCharArray();
int j = c.length;
for (int i = length - 1; i >= 0; i--) {
if (c[i] == ' ') {
c[--j] = '0';
c[--j] = '2';
c[--j] = '%';
} else {
c[--j] = c[i];
}
}
return new String(c, j, c.length - j);
}
}
```

### ...
Expand Down
17 changes: 16 additions & 1 deletion lcci/01.03.String to URL/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,22 @@ class Solution:
### Java

```java

class Solution {
public String replaceSpaces(String S, int length) {
char[] c = S.toCharArray();
int j = c.length;
for (int i = length - 1; i >= 0; i--) {
if (c[i] == ' ') {
c[--j] = '0';
c[--j] = '2';
c[--j] = '%';
} else {
c[--j] = c[i];
}
}
return new String(c, j, c.length - j);
}
}
```

### ...
Expand Down
16 changes: 16 additions & 0 deletions lcci/01.03.String to URL/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public String replaceSpaces(String S, int length) {
char[] c = S.toCharArray();
int j = c.length;
for (int i = length - 1; i >= 0; i--) {
if (c[i] == ' ') {
c[--j] = '0';
c[--j] = '2';
c[--j] = '%';
} else {
c[--j] = c[i];
}
}
return new String(c, j, c.length - j);
}
}