Build an Array With Stack Operations LeetCode solution in Java

1
class Solution {
2
public List<String> buildArray(int[] target, int n) {
3
List<String> result = new ArrayList<>();
4
int i = 1, j = 0;
5
while (j < target.length) {
6
result.add("Push");
7
if (i == target[j]) {
8
j++;
9
} else {
10
result.add("Pop");
11
}
12
i++;
13
}
14
return result;
15
}
16
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0