class Solution { func countBits(_ n: Int) -> [Int] { var bits = [Int](repeating: 0, count: n + 1) var highBit = 0 for i in 1...n { if !(i & i - 1) { highBit = i } bits[i] = bits[i - highBit] + 1 } return bits } }

class Solution public vectorint countBitsint n vectorint bitsn + 1; int highBit = 0; for int i = 1; i = n; i++ if !i & i - 1 highBit = i; bitsi = bitsi

原文地址: https://www.cveoy.top/t/topic/itYC 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录