카테고리 없음

powerOfTwo

루트노드 2015. 3. 17. 23:12

106 Chrs

int i,s=1;
int[] powerOfTwo(int N) {
        int[] a = new int[Long.bitCount(N)];
        for (;s>0;s*=2)
            if (0 < (N & s))
                a[i++]=s;
          
        return a;

}


112 Chrs

int[] powerOfTwo(int N) {
int i=0,s=1,c=Long.bitCount(N);
        int[] a = new int[c];
        for (;i<c;s*=2)
            if (0 < (N & s))
                a[i++]=s;
           
        return a;

}


112 Chrs

int i;
int[] powerOfTwo(int N) {
        int[] a = new int[Long.bitCount(N)];
        for (;N>0;)
            N-=a[i++] = Integer.lowestOneBit(N);
        return a;
}