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
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -177,15 +177,26 @@
     
-// TODO
+Arrays.sort(nums);
 %0A   
@@ -204,22 +204,23 @@
     
-return
+int i =
  0;%0A    
 %7D%0A%0A 
@@ -219,174 +219,159 @@
     
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem561 prob = new Problem561();%0A        System.out.println(prob.arrayPairSum(new int%5B%5D%7B1, 4, 3, 2%7D)); // 4
+int sum = 0;%0A        while (i %3C nums.length) %7B%0A            sum += Math.min(nums%5Bi%5D, nums%5Bi + 1%5D);%0A            i += 2;%0A        %7D%0A        return sum;
 %0A   

Solve problem 561