jd笔试 问一下大佬有过的吗?
第一题寻找木头
public class xunzaomutou { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] res = new int[n]; int count = 0; for (int i = 0; i < n; i++) { res[i] = sc.nextInt(); } int[] tmp= Arrays.copyOf(res,n); Arrays.sort(tmp); int max = tmp[n-1]; int min = tmp[0]; int maxindex = 0; int minindex = 0; for (int i = 0; i < n; i++) { if(res[i] == min){ minindex = i; }else if(res[i] == max){ maxindex = i; } } count = Math.min(maxindex - minindex+1, minindex+1+n-1-maxindex+1); System.out.println(count); } }class是main ,这代码过不了吗?有大佬A了吗想参考看看
第二题大佬有A了的吗参考一下
#笔经#