Skip to content

Commit 428ea42

Browse files
committed
🎉 feat: initial commit for leetcode 338 using Swift
1 parent da1edfd commit 428ea42

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Swift/338. Counting Bits.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// 338. Counting Bits
2+
// 28ms
3+
func countBits(_ num: Int) -> [Int] {
4+
var arr = Array(repeating: 0, count: num+1), i = 0
5+
while i <= num {
6+
arr[i] = i.nonzeroBitCount
7+
i += 1
8+
}
9+
10+
return arr
11+
}

0 commit comments

Comments
 (0)