One line Java solution


  • 0
    N
    public int[] countBits(int num) {
      return IntStream.range(0, num + 1).map(i -> Integer.bitCount(i)).toArray();
    }
    

    Not fast (probably because of using the IntStream and some autoboxing) but it is concise.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.