京东笔试4.16
编程题1:只过了90%
//public class Main{ // public static void main(String[] args){ // Scanner sc = new Scanner(System.in); // int T = Integer.parseInt(sc.nextLine().trim()); // while(T-- > 0){ // int n = Integer.parseInt(sc.nextLine().trim()); // Stack<String> s = new Stack<>(); // for(int i = 0; i < n; i++){ // s.push(sc.nextLine().trim()); // } // if(isOk(s)){ // System.out.println("Yes"); // }else { // System.out.println("No"); // } // // } // } // // public static boolean isOk(Stack<String> s){ // Stack<String> rs = new Stack<>(); // while (!s.isEmpty()){ // String temp1 = s.pop(); // if(!temp1.contains("end")){ // if(rs.isEmpty()) return false; // String temp2 = rs.pop(); // if(temp2.contains(temp1)) continue; // return false; // } // if(temp1.contains(s.peek()) && !s.peek().contains("end")){ // s.pop(); // continue; // } // rs.push(temp1); // } // // return true; // } //}2:只过了18%,为啥呀,希望指点一二。
public class Main { static int max = 0; static List<Integer> combine = new LinkedList<>(); public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); while (T-- > 0) { int n = sc.nextInt(); int[] nums = new int[n]; for (int i = 0; i < n; i++) { nums[i] = sc.nextInt(); } max = 0; isMax(nums); System.out.println(max); } } public static void isMax(int[] nums){ int n = nums.length; for(int i = 0; i < n; i++){ int l = i; int r = n-i-1; if(l/2 > r) break; if(r/2 > l || l/2 > r) continue; max = Math.max(max, nums[i]); } } }