modified offer05. Add two python versions.

This commit is contained in:
Camille0512
2022-02-27 00:41:18 +08:00
parent 0738423c9e
commit f862ebf0c7

View File

@ -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:
```js
/**
* @param {string} s