easy SWIFT solution


  • 0
    B
    class Solution {
        func countBits(_ num: Int) -> [Int] {
        var array = [Int]()
        for n in 0...num
        {  let c = String(n, radix: 2).characters.filter{ $0 == "1"}.count
        array.append(c)  }
        return array
      }}
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.