题解 | #求int型正整数在内存中存储时1的个数#
求int型正整数在内存中存储时1的个数
https://www.nowcoder.com/practice/440f16e490a0404786865e99c6ad91c9
import Foundation while let line = readLine() { var number = Int(line)! if number == 0 { print("0") continue } var count = 0 while number > 0 { if number & 1 == 1 { count += 1 } number = number >> 1 } print(count) // let parts = line.split(separator: " ") // print(Int(parts[0])! + Int(parts[1])!) }