京东笔试4.16
求指点
第一题 为啥只通过36%
 public class TestDemo {
         public static void main(String[] args) {
             Scanner sc = new Scanner(System.in);
             int count = sc.nextInt();
             for(int i=0;i<count;i++){
                 int n = sc.nextInt();
                 sc.nextLine();
                 Deque<String> stack = new ArrayDeque<>();
                 boolean flag = true;
                 for(int j=0;j<n;j++){
                     String[] s = sc.nextLine().split(" ");
                     if(s.length==1){
                         stack.push(s[0]);
                     }else if(stack.size()==0 || !stack.pop().equals(s[1])){
                         flag = false;
                         break;
                     }
                 }
                 if(stack.size()==0 && flag){
                     System.out.println("Yes");
                 }else{
                     System.out.println("No");
                 }
             }
         }
     }
 第二题只通过18
 public class TestDemo {
             static List<Integer> list;
             static int max;
             public static void main(String[] args) {
                 Scanner sc = new Scanner(System.in);
                 int count = sc.nextInt();
                 for(int i=0;i<count;i++){
                     max = Integer.MIN_VALUE;
                     list = new ArrayList<>();
                     int n = sc.nextInt();
                     int[] nums = new int[n];
                     for(int j=0;j<n;j++){
                         nums[j] = sc.nextInt();
                     }
                     helper(nums,0,false);
                     System.out.println(max);
                 }
             }
             public static void helper(int[] nums,int pos,boolean flag){
                 if(pos==nums.length){
                     int val = list.get((list.size()-1)/2);
                     if(val==5){
                         System.out.println(list);
                     }
                     max = Math.max(val,max);
                     return;
                 }
                 // 如果flag为false,说明前一个使用了,可以跳过当前
                 if(!flag){
                     helper(nums,pos+1,true);
                 }
                 // 使用当前
                 list.add(nums[pos]);
                 helper(nums,pos+1,false);
                 list.remove(list.size()-1);
             }
         }
     
查看14道真题和解析