//想问这个是上机还是笔试手写校招的题目呀。第四题。 class Solution{     public void me(int[] a,int[]b)     {         Stack<Integer>stack=new Stack<>();         int len=a.length;         int maxa=Integer.MIN_VALUE;         int minb=Integer.MAX_VALUE;         for(int i=0;i<len;i++)         {             if(a[i]>maxa)maxa=a[i];             if(b[i]<minb)minb=b[i];             if(maxa<minb) {stack.push(i);continue;}                          if(a[i]<b[i]) {                 maxa=a[i];                 minb=b[i];                 stack.push(-1);                 stack.push(i);                 //System.out.print(stack.peek()+" ");                 continue;             }             else {                 maxa=Integer.MIN_VALUE;                 minb=Integer.MAX_VALUE;                 stack.push(-1);                 //压栈完毕             }         }         int count=1;         int sum=0;                  while(!stack.isEmpty())         {             int pre=stack.pop();//判定连续             if(!stack.isEmpty())             {             if(stack.peek()!=-1)             {                 count++;continue;             }             else {                 stack.pop();                 sum+=count*(count+1)/2;                 count=1;continue;             }             }                              sum+=count*(count+1)/2;                      }         System.out.print(sum);     } }
点赞 评论

相关推荐

双尔:反手回一个很抱歉,经过慎重考虑,您与我的预期暂不匹配,感谢您的投递
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务