0541.反转字符串II.md 增加Python版本实现3
This commit is contained in:
parent
42d84f8a7f
commit
a4cafe0ce7
|
|
@ -282,7 +282,7 @@ class Solution:
|
||||||
return ''.join(res)
|
return ''.join(res)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Python3 (v2):
|
#### Python3 (v2):
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class Solution:
|
class Solution:
|
||||||
|
|
@ -297,6 +297,20 @@ class Solution:
|
||||||
return s
|
return s
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Python3 (v3):
|
||||||
|
```python
|
||||||
|
class Solution:
|
||||||
|
def reverseStr(self, s: str, k: int) -> str:
|
||||||
|
i = 0
|
||||||
|
chars = list(s)
|
||||||
|
|
||||||
|
while i < len(chars):
|
||||||
|
chars[i:i + k] = chars[i:i + k][::-1] # 反转后,更改原值为反转后值
|
||||||
|
i += k * 2
|
||||||
|
|
||||||
|
return ''.join(chars)
|
||||||
|
```
|
||||||
|
|
||||||
### Go:
|
### Go:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue