← 返回 uber 的题目列表Minimum Operations to Make n Zero
类型:online_judge
Given an integer n, find the minimum number of operations to make it zero where each operation consists of either adding or subtracting some power of two.
Example:
Input: n = 39 Output: 4 Explanation:
39 to 38 (subtract 2^0)
38 to 19 (subtract 2^1)
19 to 18 (subtract 2^0)
18 to 0 (subtract 2^1)
Constraints: 1 <= n <= 10^9
Example
Input
39
Output
4