image_2021-11-05_17-43-17.png
33.9 KB
#N1441. Build an Array With Stack Operations
problem link
#solution
problem link
#solution
class Solution {
public List<String> buildArray(int[] target, int n) {
ArrayList<String> stack=new ArrayList<String>();
int x=0;
for(int i=1;i<=n && x<target.length; i++){
stack.add("Push");
if(target[x]==i) x++;
else stack.add("Pop");
}
return stack;
}
}