You are viewing a single comment's thread. Return to all comments →
my solution implemented from above in a single classs
import java.io.; import java.util.; import java.lang.*;
public class Solution { int value,max2;
public static void main(String[] args) { Scanner scan=new Scanner(System.in); int n=scan.nextInt(); Stack<Solution> stack=new Stack<Solution>(); int max=-1; for(int i=0;i<n;i++) { int k=scan.nextInt(); if(k==1) { int d=scan.nextInt(); max=Math.max(d,max); Solution ob=new Solution(d,max); stack.add(ob); } else if(k==2) { stack.pop(); if(stack.empty()==true) max=-1; else max=stack.peek().max2; } else { System.out.println(stack.peek().max2); } } } public Solution(int v,int m) { this.value=v; this.max2=m; }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Element
You are viewing a single comment's thread. Return to all comments →
my solution implemented from above in a single classs
import java.io.; import java.util.; import java.lang.*;
public class Solution { int value,max2;
}