mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-06 23:28:29 +08:00
Merge pull request #2791 from gazeldx/l541
0541.反转字符串II.md 增加Python版本实现3
This commit is contained in:
@ -282,7 +282,7 @@ class Solution:
|
||||
return ''.join(res)
|
||||
```
|
||||
|
||||
### Python3 (v2):
|
||||
#### Python3 (v2):
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
@ -297,6 +297,21 @@ class Solution:
|
||||
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
|
||||
|
Reference in New Issue
Block a user