Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit 526f46a

Browse files
committed
added problem67
1 parent 079e846 commit 526f46a

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

problem67/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# 338. Counting Bits
2+
3+
Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1's in the binary representation of i.
4+
5+
6+
## Example 1:
7+
8+
Input: n = 2
9+
Output: [0,1,1]
10+
Explanation:
11+
0 --> 0
12+
1 --> 1
13+
2 --> 10
14+
15+
## Example 2:
16+
17+
Input: n = 5
18+
Output: [0,1,1,2,1,2]
19+
Explanation:
20+
0 --> 0
21+
1 --> 1
22+
2 --> 10
23+
3 --> 11
24+
4 --> 100
25+
5 --> 101
26+
27+
28+
## Constraints:
29+
30+
0 <= n <= 105
31+
32+
33+
## Follow up:
34+
35+
It is very easy to come up with a solution with a runtime of O(n log n). Can you do it in linear time O(n) and possibly in a single pass?
36+
Can you do it without using any built-in function (i.e., like __builtin_popcount in C++)?

0 commit comments

Comments
 (0)