modified offer05. Add two python versions.
This commit is contained in:
parent
0738423c9e
commit
f862ebf0c7
|
|
@ -260,8 +260,24 @@ class Solution:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
class Solution:
|
||||||
|
def replaceSpace(self, s: str) -> str:
|
||||||
|
# method 1 - Very rude
|
||||||
|
return "%20".join(s.split(" "))
|
||||||
|
|
||||||
|
# method 2 - Reverse the s when counting in for loop, then update from the end.
|
||||||
|
n = len(s)
|
||||||
|
for e, i in enumerate(s[::-1]):
|
||||||
|
print(i, e)
|
||||||
|
if i == " ":
|
||||||
|
s = s[: n - (e + 1)] + "%20" + s[n - e:]
|
||||||
|
print("")
|
||||||
|
return s
|
||||||
|
```
|
||||||
|
|
||||||
javaScript:
|
javaScript:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
/**
|
/**
|
||||||
* @param {string} s
|
* @param {string} s
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue