@Test public void countingBitsWisdom() { assertNull(CountingBitsSolution.countBitsWisdom(-1)); assertEquals(0, CountingBitsSolution.countBitsWisdom(0)[0]); int[] result = CountingBitsSolution.countBitsWisdom(5); int[] except = new int[]{0, 1, 1, 2, 1, 2}; for (int i = 0; i < 5; i++) { assertEquals(except[i], result[i]); } long b = System.currentTimeMillis(); CountingBitsSolution.countBitsWisdom(SUPPRESS_TEST_LIMITATION); long e = System.currentTimeMillis(); System.out.println(e - b); }
static int[] countBitsWisdom(int num) { if (num < 0) return null; int[] f = new int[num + 1]; for (int i = 1; i <= num; i++) f[i] = f[i >> 1] + (i & 1); return f; }
CountingBitsSolution { static int[] countBitsWisdom(int num) { if (num < 0) return null; int[] f = new int[num + 1]; for (int i = 1; i <= num; i++) f[i] = f[i >> 1] + (i & 1); return f; } }
CountingBitsSolution { static int[] countBitsWisdom(int num) { if (num < 0) return null; int[] f = new int[num + 1]; for (int i = 1; i <= num; i++) f[i] = f[i >> 1] + (i & 1); return f; }  }
CountingBitsSolution { static int[] countBitsWisdom(int num) { if (num < 0) return null; int[] f = new int[num + 1]; for (int i = 1; i <= num; i++) f[i] = f[i >> 1] + (i & 1); return f; }   }
CountingBitsSolution { static int[] countBitsWisdom(int num) { if (num < 0) return null; int[] f = new int[num + 1]; for (int i = 1; i <= num; i++) f[i] = f[i >> 1] + (i & 1); return f; }    }