package leetcode;

/**
 * https://leetcode.com/problems/reordered-power-of-2/
 */
public class Problem869 {
    public boolean reorderedPowerOf2(int N) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem869 prob = new Problem869();
        System.out.println(prob.reorderedPowerOf2(1)); // true
        System.out.println(prob.reorderedPowerOf2(10)); // false
        System.out.println(prob.reorderedPowerOf2(16)); // true
        System.out.println(prob.reorderedPowerOf2(24)); // false
        System.out.println(prob.reorderedPowerOf2(46)); // true
    }
}

@@ -159,36 +159,1036 @@
     
-// TODO%0A        return false
+if (isPower2(N)) %7B%0A            return true;%0A        %7D%0A        String s = %22%22 + N;%0A        char%5B%5D chars = s.toCharArray();%0A        return reorderedPowerOf2(chars, 0);%0A    %7D%0A%0A    private static boolean reorderedPowerOf2(char%5B%5D chars, int idx) %7B%0A        if (idx %3E= chars.length) %7B%0A            return false;%0A        %7D%0A        for (int i = 0; i %3C chars.length; i++) %7B%0A            if (i == idx) %7B%0A                continue;%0A            %7D%0A            swap(chars, idx, i);%0A            String newString = new String(chars);%0A            int n = Integer.parseInt(newString);%0A%0A            System.out.println(newString);%0A            // Backtrack.%0A            swap(chars, idx, i);%0A        %7D%0A        return reorderedPowerOf2(chars, idx + 1);%0A    %7D%0A%0A    private static void swap(char%5B%5D chars, int i, int j) %7B%0A        char tmp = chars%5Bi%5D;%0A        chars%5Bi%5D = chars%5Bj%5D;%0A        chars%5Bj%5D = tmp;%0A    %7D%0A%0A    private static boolean isPower2(int n) %7B%0A        double dsqrt = Math.sqrt(n);%0A        int isqrt = (int) dsqrt;%0A        return dsqrt - isqrt == 0
 ;%0A  
@@ -1277,24 +1277,26 @@
 oblem869();%0A
+//
         Syst
@@ -1338,32 +1338,34 @@
 f2(1)); // true%0A
+//
         System.o
@@ -1405,32 +1405,34 @@
 (10)); // false%0A
+//
         System.o
@@ -1475,24 +1475,26 @@
 )); // true%0A
+//
         Syst
@@ -1546,16 +1546,18 @@
 / false%0A
+//
         
@@ -1612,16 +1612,81 @@
 // true%0A
+        System.out.println(prob.reorderedPowerOf2(562)); // true%0A
     %7D%0A%7D%0A

Update problem 869