package leetcode;

/**
 * https://leetcode.com/problems/array-partition-i
 */
public class Problem561 {
    public int arrayPairSum(int[] nums) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem561 prob = new Problem561();
        System.out.println(prob.arrayPairSum(new int[]{1, 4, 3, 2})); // 4
    }
}

package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/array-partition-i
 */
public class Problem561 {
    public int arrayPairSum(int[] nums) {
        Arrays.sort(nums);
        int i = 0;
        int sum = 0;
        while (i < nums.length) {
            sum += Math.min(nums[i], nums[i + 1]);
            i += 2;
        }
        return sum;
    }
}

Solve problem 561