package leetcode;

/**
 * https://leetcode.com/problems/beautiful-arrangement/
 */
public class Problem526 {
    public int countArrangement(int N) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem526 prob = new Problem526();
        System.out.println(prob.countArrangement(2)); // 2
    }
}

@@ -12,16 +12,116 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.HashSet;%0Aimport java.util.List;%0Aimport java.util.Set;%0A%0A
 /**%0A * h
@@ -255,188 +255,1425 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem526 prob = new Problem526();%0A        System.out.println(prob.countArrangement(2)); // 2
+List%3CInteger%3E numbers = new ArrayList%3C%3E();%0A        for (int i = 1; i %3C= N; i++) %7B%0A            numbers.add(i);%0A        %7D%0A        IntRef result = new IntRef();%0A        countArrangement(numbers, new HashSet%3C%3E(), 1, result);%0A        return result.ref;%0A    %7D%0A%0A    private static class IntRef %7B%0A        int ref;%0A    %7D%0A%0A    private static void countArrangement(List%3CInteger%3E numbers,%0A                                         Set%3CInteger%3E processed,%0A                                         int count,%0A                                         IntRef result) %7B%0A        if (count %3E numbers.size()) %7B%0A            result.ref++;%0A            return;%0A        %7D%0A        for (int i = 0; i %3C numbers.size(); i++) %7B%0A            int val = numbers.get(i);%0A            if (processed.contains(val)) %7B%0A                continue;%0A            %7D%0A            if (val %25 count == 0 %7C%7C count %25 val == 0) %7B%0A                processed.add(val);%0A                countArrangement(numbers, processed, count + 1, result);%0A                // backtracking%0A                processed.remove(val);%0A            %7D%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem526 prob = new Problem526();%0A        System.out.println(prob.countArrangement(2)); // 2%0A        System.out.println(prob.countArrangement(3)); // 2%0A        System.out.println(prob.countArrangement(10)); // 700%0A        System.out.println(prob.countArrangement(15)); // 24679
 %0A   

Update problem 526