Skip to content

Commit c69da4f

Browse files
authored
Update and rename Build an Array With Stack Operations.java to Build an Array With Stack Operations.java
1 parent 02b74a0 commit c69da4f

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

Easy/Build an Array With Stack Operations.java

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
3+
private static final String PUSH = "Push";
4+
private static final String POP = "Pop";
5+
6+
public List<String> buildArray(int[] target, int n) {
7+
int idx = 0;
8+
List<String> result = new ArrayList<>();
9+
for (int i = 1; i <= n; i++) {
10+
if (target[idx] == i) {
11+
idx++;
12+
result.add(PUSH);
13+
} else {
14+
result.add(PUSH);
15+
result.add(POP);
16+
}
17+
if (idx == target.length) {
18+
break;
19+
}
20+
}
21+
return result;
22+
}
23+
}

0 commit comments

Comments
 (0)