Skip to content

Commit aacb26d

Browse files
Merge pull request youngyangyang04#605 from shuwenlan/master
添加 剑指Offer58-II.左旋转字符串 Python3版本 使用模+下标
2 parents 88b9733 + 0c4a4a6 commit aacb26d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

problems/剑指Offer58-II.左旋转字符串.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ class Solution:
141141
# 空间复杂度:O(n),python的string为不可变,需要开辟同样大小的list空间来修改
142142
```
143143

144+
```python 3
145+
#方法三:考虑不能用切片的情况下,利用模+下标实现
146+
class Solution:
147+
def reverseLeftWords(self, s: str, n: int) -> str:
148+
new_s = ''
149+
for i in range(len(s)):
150+
j = (i+n)%len(s)
151+
new_s = new_s + s[j]
152+
return new_s
153+
154+
```
155+
144156
Go:
145157

146158
```go

0 commit comments

Comments
 (0)