Skip to content

Commit 9ec83cc

Browse files
committed
update readme
1 parent 551f3ae commit 9ec83cc

File tree

5 files changed

+27
-132
lines changed

5 files changed

+27
-132
lines changed

1552-build-an-array-with-stack-operations/1552-build-an-array-with-stack-operations.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

1552-build-an-array-with-stack-operations/README.md

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
#time complexity: O(n)
22
#space complexity: O(1)
3-
43
from typing import List
54

65

76
class Solution:
87
def buildArray(self, target: List[int], n: int) -> List[str]:
9-
res = []
10-
index = 0
8+
result = []
9+
idx = 0
1110
for item in target:
12-
while index < item - 1:
13-
res.append("Push")
14-
res.append("Pop")
15-
index += 1
16-
res.append("Push")
17-
index += 1
18-
return res
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
1918

2019

2120
target = [1, 3]
2221
n = 3
23-
24-
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
2528
print(Solution().buildArray(target, n))

README.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,3 @@ It helps others discover the repo and keeps the project growing.
115115
---
116116

117117
Feedback / Questions → open an Issue or reach out on [LinkedIn](https://www.linkedin.com/in/hogan-l/)
118-
119-
<!---LeetCode Topics Start-->
120-
# LeetCode Topics
121-
## Array
122-
| |
123-
| ------- |
124-
| [1552-build-an-array-with-stack-operations](https://github.com/hogan-tech/leetcode-solution/tree/master/1552-build-an-array-with-stack-operations) |
125-
## Stack
126-
| |
127-
| ------- |
128-
| [1552-build-an-array-with-stack-operations](https://github.com/hogan-tech/leetcode-solution/tree/master/1552-build-an-array-with-stack-operations) |
129-
## Simulation
130-
| |
131-
| ------- |
132-
| [1552-build-an-array-with-stack-operations](https://github.com/hogan-tech/leetcode-solution/tree/master/1552-build-an-array-with-stack-operations) |
133-
<!---LeetCode Topics End-->

Readme/1441-build-an-array-with-stack-operations.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<h2><a href="https://leetcode.com/problems/build-an-array-with-stack-operations/">1441. Build an Array With Stack Operations</a></h2><h3>Medium</h3><hr><div><p>You are given an integer array <code>target</code> and an integer <code>n</code>.</p>
1+
<h2><a href="https://leetcode.com/problems/build-an-array-with-stack-operations">1552. Build an Array With Stack Operations</a></h2><h3>Medium</h3><hr><p>You are given an integer array <code>target</code> and an integer <code>n</code>.</p>
22

33
<p>You have an empty stack with the two following operations:</p>
44

55
<ul>
6-
<li><strong><code>"Push"</code></strong>: pushes an integer to the top of the stack.</li>
7-
<li><strong><code>"Pop"</code></strong>: removes the integer on the top of the stack.</li>
6+
<li><strong><code>&quot;Push&quot;</code></strong>: pushes an integer to the top of the stack.</li>
7+
<li><strong><code>&quot;Pop&quot;</code></strong>: removes the integer on the top of the stack.</li>
88
</ul>
99

1010
<p>You also have a stream of the integers in the range <code>[1, n]</code>.</p>
@@ -22,8 +22,9 @@
2222
<p>&nbsp;</p>
2323
<p><strong class="example">Example 1:</strong></p>
2424

25-
<pre><strong>Input:</strong> target = [1,3], n = 3
26-
<strong>Output:</strong> ["Push","Push","Pop","Push"]
25+
<pre>
26+
<strong>Input:</strong> target = [1,3], n = 3
27+
<strong>Output:</strong> [&quot;Push&quot;,&quot;Push&quot;,&quot;Pop&quot;,&quot;Push&quot;]
2728
<strong>Explanation:</strong> Initially the stack s is empty. The last element is the top of the stack.
2829
Read 1 from the stream and push it to the stack. s = [1].
2930
Read 2 from the stream and push it to the stack. s = [1,2].
@@ -33,8 +34,9 @@ Read 3 from the stream and push it to the stack. s = [1,3].
3334

3435
<p><strong class="example">Example 2:</strong></p>
3536

36-
<pre><strong>Input:</strong> target = [1,2,3], n = 3
37-
<strong>Output:</strong> ["Push","Push","Push"]
37+
<pre>
38+
<strong>Input:</strong> target = [1,2,3], n = 3
39+
<strong>Output:</strong> [&quot;Push&quot;,&quot;Push&quot;,&quot;Push&quot;]
3840
<strong>Explanation:</strong> Initially the stack s is empty. The last element is the top of the stack.
3941
Read 1 from the stream and push it to the stack. s = [1].
4042
Read 2 from the stream and push it to the stack. s = [1,2].
@@ -43,8 +45,9 @@ Read 3 from the stream and push it to the stack. s = [1,2,3].
4345

4446
<p><strong class="example">Example 3:</strong></p>
4547

46-
<pre><strong>Input:</strong> target = [1,2], n = 4
47-
<strong>Output:</strong> ["Push","Push"]
48+
<pre>
49+
<strong>Input:</strong> target = [1,2], n = 4
50+
<strong>Output:</strong> [&quot;Push&quot;,&quot;Push&quot;]
4851
<strong>Explanation:</strong> Initially the stack s is empty. The last element is the top of the stack.
4952
Read 1 from the stream and push it to the stack. s = [1].
5053
Read 2 from the stream and push it to the stack. s = [1,2].
@@ -61,4 +64,3 @@ The answers that read integer 3 from the stream are not accepted.
6164
<li><code>1 &lt;= target[i] &lt;= n</code></li>
6265
<li><code>target</code> is strictly increasing.</li>
6366
</ul>
64-
</div>

0 commit comments

Comments
 (0)