mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 08:50:15 +08:00
modified 541. Can be more pythonic.
This commit is contained in:
@ -204,8 +204,23 @@ class Solution:
|
|||||||
return ''.join(res)
|
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:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func reverseStr(s string, k int) string {
|
func reverseStr(s string, k int) string {
|
||||||
ss := []byte(s)
|
ss := []byte(s)
|
||||||
|
Reference in New Issue
Block a user