京东笔试教室怎么搞啊?(附第一题JAVA)
public class GouDong {
public static void main(String[] args){
System.out.println(Integer.MAX_VALUE);
new GouDong().exam1();
}
public void exam1(){
Scanner in = new Scanner(System.in);
while(in.hasNext()){
int n = in.nextInt();
int[] high = new int[n];
for(int i=0;i<n;i++){
high[i]=in.nextInt();
}
Stack<Integer> max = new Stack<Integer>();
Stack<Integer> min = new Stack<Integer>();
max.push(high[0]);
min.push(high[0]);
for(int i=1;i<n;i++){
if(high[i]>=max.peek()){
max.push(high[i]);
min.push(high[i]);
continue;
}
if(high[i]>=min.peek())
continue;
int maxtmp=max.pop();
int mintmp=min.pop();
while(!max.empty()&&high[i]<max.peek()){
max.pop();
mintmp=min.pop();
}
if(mintmp>high[i])
mintmp=high[i];
max.push(maxtmp);
min.push(mintmp);
}
System.out.println(max.size());
}
}
} #京东##笔试题目#


查看9道真题和解析