1 package solution44; 2 3 import java.util.*; 4 class Solution { 5 public int solution(int n,int[] nums) { 6 Arrays.sort(nums); 7 int maxVal = nums[n-1]; 8 int sums = 0; 9 for(int i=0;i<n-1;i++){ 10 sums += (nums[i] + maxVal) / 2; 11 } 12 return sums; 13 } 14 }
算法思路:数组排序。