We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 367a862 commit 47cdcb0Copy full SHA for 47cdcb0
counting-bits/yhkee0404.swift
@@ -0,0 +1,9 @@
1
+class Solution {
2
+ func countBits(_ n: Int) -> [Int] {
3
+ var ans = Array(repeating: 0, count: n + 1) // S(n) = O(n)
4
+ for i in 1..<n+1 { // T(n) = O(n)
5
+ ans[i] = ans[i >> 1] + (i & 1)
6
+ }
7
+ return ans
8
9
+}
0 commit comments