diff --git a/counting-bits/DaleSeo.rs b/counting-bits/DaleSeo.rs new file mode 100644 index 000000000..ca67dbe71 --- /dev/null +++ b/counting-bits/DaleSeo.rs @@ -0,0 +1,12 @@ +// TC: O(n) +// SC: O(n) +impl Solution { + pub fn count_bits(n: i32) -> Vec { + let n = n as usize; + let mut ans = vec![0i32; n + 1]; + for i in 1..=n { + ans[i] = ans[i >> 1] + (i & 1) as i32; + } + ans + } +}