Skip to content

Commit c5633c2

Browse files
authored
Create build-an-array-with-stack-operations.py
1 parent 2a51c20 commit c5633c2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def buildArray(self, target: List[int], n: int) -> List[str]:
3+
output = []
4+
cur = 1
5+
for item in target:
6+
while cur < item:
7+
output.append("Push")
8+
output.append("Pop")
9+
cur += 1
10+
11+
output.append("Push")
12+
cur += 1
13+
return output

0 commit comments

Comments
 (0)