阿里笔试330
直接只做了第二题。。。一直卡在30%超时,最后一分钟想出一个办法,应该能ac吧,大佬帮忙看看
public static void avg(int[] nums){ double sum = 0; int len = nums.length; int t = (len+1)*len/2; int max = 0; for (int i = nums.length-1; i >= 0; i--) { sum+=nums[i]; nums[i] = Math.max(max, nums[i]); } for (int i = 0; i < len; i++) { for (int j = i+1; j < len; j++) { sum+=nums[j]; } } System.out.format("%#.6f", sum*1.0/t); }