mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
modified 541. Can be more pythonic.
This commit is contained in:
@ -204,8 +204,23 @@ class Solution:
|
||||
return ''.join(res)
|
||||
```
|
||||
|
||||
Python3 (v2):
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
def reverseStr(self, s: str, k: int) -> str:
|
||||
# Two pointers. Another is inside the loop.
|
||||
p = 0
|
||||
while p < len(s):
|
||||
p2 = p + k
|
||||
# Written in this could be more pythonic.
|
||||
s = s[:p] + s[p: p2][::-1] + s[p2:]
|
||||
p = p + 2 * k
|
||||
return s
|
||||
```
|
||||
|
||||
Go:
|
||||
|
||||
```go
|
||||
func reverseStr(s string, k int) string {
|
||||
ss := []byte(s)
|
||||
|
Reference in New Issue
Block a user