로딩
요청 처리 중입니다...

JAVA_LeetCode 3774_Absolute Difference Between Maximum and Minimum K Elements

 JAVA_LeetCode 3774_Absolute Difference Between Maximum and Minimum K Elements

JAVA_LeetCode 3774_Absolute Difference Between Maximum and Minimum K Elements 풀이 import java.util.*; class Solution { public int absDifference(int[] nums, int k) { int minSum = 0, maxSum = 0, chk = 0, temp = k; int[] cnt = new int[101]; for(int num : nums) cnt[num]++; for(int i = 1; i <= 100 && temp > 0; i++){ chk = Math.min(cnt[i], temp); minSum += i * chk; temp -= chk; } temp = k; for(int i = 100; i >= 1 && temp > 0; i--){ chk = Math.min(cnt[i], temp); maxSum += i * chk; temp -= chk; } return ...