We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cfca263 commit 3dc4167Copy full SHA for 3dc4167
problems/剑指Offer58-II.左旋转字符串.md
@@ -119,6 +119,27 @@ class Solution {
119
```
120
Python:
121
122
+```python
123
+# 方法一:可以使用切片方法
124
+class Solution:
125
+ def reverseLeftWords(self, s: str, n: int) -> str:
126
+ return s[n:] + s[0:n]
127
+
128
+# 方法二:也可以使用上文描述的方法,有些面试中不允许使用切片,那就使用上文作者提到的方法
129
+# class Solution:
130
+# def reverseLeftWords(self, s: str, n: int) -> str:
131
+# s = list(s)
132
+# s[0:n] = list(reversed(s[0:n]))
133
+# s[n:] = list(reversed(s[n:]))
134
+# s.reverse()
135
136
+# return "".join(s)
137
138
139
+# 时间复杂度:O(n)
140
+# 空间复杂度:O(n),python的string为不可变,需要开辟同样大小的list空间来修改
141
+```
142
143
Go:
144
145
```go
0 commit comments