mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 07:35:35 +08:00
0541.反转字符串II.md 增加Python版本实现3
This commit is contained in:
@ -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
|
||||||
|
Reference in New Issue
Block a user