Skip to content

Commit ecbab82

Browse files
committed
Time: 0 ms (100%), Space: 18 MB (13.08%) - LeetHub
1 parent ed1758a commit ecbab82

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#time complexity: O(n)
2+
#space complexity: O(1)
3+
from typing import List
4+
5+
6+
class Solution:
7+
def buildArray(self, target: List[int], n: int) -> List[str]:
8+
result = []
9+
idx = 0
10+
for item in target:
11+
while idx < item - 1:
12+
result.append("Push")
13+
result.append("Pop")
14+
idx += 1
15+
result.append("Push")
16+
idx += 1
17+
return result
18+
19+
20+
target = [1, 3]
21+
n = 3
22+
print(Solution().buildArray(target, n))
23+
target = [1, 2, 3]
24+
n = 3
25+
print(Solution().buildArray(target, n))
26+
target = [1, 2]
27+
n = 4
28+
print(Solution().buildArray(target, n))

0 commit comments

Comments
 (0)