mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-11 13:00:22 +08:00
modified offer05. Add two python versions.
This commit is contained in:
@ -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
|
||||||
|
Reference in New Issue
Block a user