[Java] - count occurance of digits
From the problem description it is clear that we need to check whether N is a permutation of a power of 2. The approach is the following:\n\nIn the first step, 
From the problem description it is clear that we need to check whether N is a permutation of a power of 2. The approach is the following:\n\nIn the first step, we count the occurance of each digit (0-9) in N\n\nIn the second step, we go through each power of 2 (say, x). For each x, we do the following:\n1. Count the occurance of each digit in x\n2. We compare the occurance of digits in x with that of N. If we find a match, we return true.\n3. If we don\'t find a match for any x, we return false.\n\nFor example, for N = 83461, the counts will match for x = 16384 and thus we will return true. For, N = 10000, the counts will not match for any x, so we will return false.\n\n```\n\tpublic boolean reorderedPowerOf2(int N) {\n        int[] dcountN = getDigitCount(N);\n        \n        for(int i = 0; i < 31; i++){\n            int x = 1 << i, j;\n            int[] dcountX = getDigitCount(x);\n            \n            for(j = 0; j < 10 && dcountN[j] == dcountX[j]; j++);\n\t\t\t/*if j becomes 10 after above loop, it means the counts\n\t\t\t  of the digits are the same in x and N*/\n            if(j == 10) return true;\n        }\n        \n        return false;\n    }\n    \n    private int[] getDigitCount(int x){\n        int[] result = new int[10];\n        while(x > 0){\n            result[x % 10]++;\n            x /= 10;\n        }\n        return result;\n    }
[]