Build an Array With Stack Operations LeetCode solution in Python

1
class Solution:
2
def buildArray(self, target: List[int], n: int) -> List[str]:
3
temp = []
4
result = []
5
x = target[-1]
6
for i in range(1, x + 1):
7
temp.append(i)
8
for i in range(len(temp)):
9
if temp[i] in target:
10
result.append("Push")
11
elif temp[i] not in target:
12
result.append("Push")
13
result.append("Pop")
14
return result

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0