191. Number of 1 Bits ¶
Approach 1: Naive¶
- Time: $O(32) = O(1)$
- Space: $O(1)$
1 2 3 4 5 6 7 8 9 10 11 12 |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
|
1 2 3 4 5 6 7 8 9 |
|
Approach 2: Built-in¶
- Time: $O(1)$
- Space: $O(1)$
1 2 3 4 5 6 |
|
1 2 3 4 5 6 |
|
1 2 3 |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
|
1 2 3 4 5 6 7 8 9 |
|
1 2 3 4 5 6 |
|
1 2 3 4 5 6 |
|
1 2 3 |
|