题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
Java 代码
import java.util.*;
public class Main {
public static int helper(int[] nums) {
Arrays.sort(nums);
int len = nums.length;
int ans = 0;
for (int i = 0; i < len / 2; i++) {
ans += nums[len - 1 - i] - nums[i];
}
return ans;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int n = scanner.nextInt();
int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = scanner.nextInt();
}
System.out.println(helper(nums));
}
}
}