Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions counting-bits/delight010.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Solution {
func countBits(_ n: Int) -> [Int] {
// Time O(n log n)
// Space O(1)
var result: [Int] = []
var count = 0
var num = 0

while num <= n {
var temp = num

while temp != 0 {
if temp & 1 == 1 {
count += 1
}
temp >>= 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 temp >>= 1 이 하는 역할이 뭘까요 ? swfit는 처음이라 신기하네요 ㅎㅎ

}

result.append(count)
count = 0
num += 1
}

return result
}
}