Skip to content

Latest commit

 

History

History
73 lines (31 loc) · 1.24 KB

File metadata and controls

73 lines (31 loc) · 1.24 KB

中文文档

Description

Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.

Example 1:

Input: 2

Output: [0,1,1]

Example 2:

Input: 5

Output: [0,1,1,2,1,2]

Follow up:

    <li>It is very easy to come up with a solution with run time <b>O(n*sizeof(integer))</b>. But can you do it in linear time <b>O(n)</b> /possibly in a single pass?</li>
    
    <li>Space complexity should be <b>O(n)</b>.</li>
    
    <li>Can you do it like a boss? Do it without using any builtin function like <b>__builtin_popcount</b> in c++ or in any other language.</li>
    

Solutions

Python3

Java

...