You are viewing a single comment's thread. Return to all comments →
Java
Following is a single stack solution for those who are interested
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); int queries = sc.nextInt(); int command=0; Stack<Integer> stack = new Stack<>(); while(queries>0){ command=sc.nextInt(); if(command==1){ stack.push(sc.nextInt()); }else if(command==2){ stack.remove(0); }else if(command==3){ System.out.println(stack.get(0)); } queries--; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Queue using Two Stacks
You are viewing a single comment's thread. Return to all comments →
Java
Following is a single stack solution for those who are interested
public static void main(String[] args) {