-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaximumElement-java
More file actions
45 lines (38 loc) · 1.14 KB
/
MaximumElement-java
File metadata and controls
45 lines (38 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be nahmed Solution. */
Scanner sc = new Scanner(System.in);
Stack<Integer> st = new Stack<Integer>();
Stack<Integer> st1 = new Stack<Integer>();
int t = sc.nextInt();
while(t-->0){
int s = sc.nextInt();
if(s==1){
int a = sc.nextInt();
if(st.size()==0){
st1.push(a);
st.push(a);
}
else{
if(a>=st1.peek()){
st1.push(a);
}
st.push(a);
}
}
if(s==2){
if((int)st1.peek()==(int)st.peek())
st1.pop();
st.pop();
}
if(s==3){
System.out.println(st1.peek());
}
}
}
}