Skip to content

Commit 9630f40

Browse files
authored
Create build-an-array-with-stack-operations.py
1 parent 65c0bbc commit 9630f40

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def buildArray(self, target, n):
6+
"""
7+
:type target: List[int]
8+
:type n: int
9+
:rtype: List[str]
10+
"""
11+
result, curr = [], 1
12+
for t in target:
13+
result.extend(["Push", "Pop"]*(t-curr))
14+
result.append("Push")
15+
curr = t+1
16+
return result

0 commit comments

Comments
 (0)