添加 剑指Offer58-II.左旋转字符串 Python3版本 使用模+下标
考虑不能用切片的情况下,利用模+下标实现
This commit is contained in:
parent
4028047d9d
commit
0c4a4a68ce
|
|
@ -141,6 +141,18 @@ class Solution:
|
|||
# 空间复杂度:O(n),python的string为不可变,需要开辟同样大小的list空间来修改
|
||||
```
|
||||
|
||||
```python 3
|
||||
#方法三:考虑不能用切片的情况下,利用模+下标实现
|
||||
class Solution:
|
||||
def reverseLeftWords(self, s: str, n: int) -> str:
|
||||
new_s = ''
|
||||
for i in range(len(s)):
|
||||
j = (i+n)%len(s)
|
||||
new_s = new_s + s[j]
|
||||
return new_s
|
||||
|
||||
```
|
||||
|
||||
Go:
|
||||
|
||||
```go
|
||||
|
|
|
|||
Loading…
Reference in New Issue