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 }

算法思路:数组排序。

posted on 2020-03-07 05:58  Sempron2800+  阅读(219)  评论(0编辑  收藏  举报