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 be03324 commit aa4408fCopy full SHA for aa4408f
1441.用栈操作构建数组/1441-用栈操作构建数组.py
@@ -0,0 +1,29 @@
1
+class Solution(object):
2
+ def buildArray(self, target, n):
3
+ """
4
+ :type target: List[int]
5
+ :type n: int
6
+ :rtype: List[str]
7
8
+ pre = 1
9
+ res = []
10
+ for i, num in enumerate(target):
11
+ if i == 0:
12
+ res += (num - pre) * ["Push", "Pop"] + ["Push"]
13
+ else:
14
+ res += (num - pre - 1) * ["Push", "Pop"] + ["Push"]
15
+ pre = num
16
+ return res
17
+
18
+# i = 0 #index
19
+# j = 1 #num for num in range(1, n)
20
+# res = []
21
+# while i < len(target):
22
+# if target[i] == j:
23
+# res += ["Push"]
24
+# i += 1
25
+# else:
26
+# res += ["Push", "Pop"]
27
+# j += 1
28
29
+# return res
0 commit comments