package leetcode;

/**
 * https://leetcode.com/problems/matchsticks-to-square/
 */
public class Problem473 {
    public boolean makesquare(int[] nums) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem473 prob = new Problem473();
        System.out.println(prob.makesquare(new int[]{1, 1, 2, 2, 2})); // true
        System.out.println(prob.makesquare(new int[]{3, 3, 3, 3, 4})); // false
        System.out.println(prob.makesquare(new int[]{1, 1, 1, 1, 1, 1, 1, 1})); // true
        System.out.println(prob.makesquare(new int[]{3, 5, 4, 4, 6, 2, 1, 1, 1, 5})); // true
    }
}

@@ -158,36 +158,598 @@
     
-// TODO%0A        return false
+int sum = 0;%0A        for (int num : nums) %7B%0A            sum += num;%0A        %7D%0A        int length = sum / 4;%0A        int remainder = sum %25 4;%0A        if (remainder != 0) %7B%0A            return false;%0A        %7D%0A%0A        return true;%0A    %7D%0A%0A    private static boolean makeSquare(int%5B%5D nums, int length) %7B%0A        if (length %3C 0) %7B%0A            return false;%0A        %7D%0A        if (length == 0) %7B%0A            return true;%0A        %7D%0A        boolean valid = false;%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            valid %7C= makeSquare(nums, length - nums%5Bi%5D);%0A        %7D%0A        return valid
 ;%0A  
@@ -913,32 +913,32 @@
 , 2%7D)); // true%0A
-
         System.o
@@ -1001,16 +1001,96 @@
 / false%0A
+        System.out.println(prob.makesquare(new int%5B%5D%7B3, 3, 3, 3, 3%7D)); // false%0A
         

Update problem 473