
g0501_0600.s0561_array_partition_i.Solution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java17 Show documentation
Show all versions of leetcode-in-java17 Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
package g0501_0600.s0561_array_partition_i;
// #Easy #Array #Sorting #Greedy #Counting_Sort
// #2022_03_20_Time_18_ms_(31.77%)_Space_53.6_MB_(59.76%)
import java.util.Arrays;
public class Solution {
public int arrayPairSum(int[] nums) {
Arrays.sort(nums);
int sum = 0;
for (int i = 0; i < nums.length - 1; i = i + 2) {
sum += Math.min(nums[i], nums[i + 1]);
}
return sum;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy