1
 2
 3
 4
 5
 6
 7
 8
 9
10
// @Title: 将数字变成 0 的操作次数 (Number of Steps to Reduce a Number to Zero)
// @Author: 15816537946@163.com
// @Date: 2022-01-31 10:19:07
// @Runtime: 0 ms
// @Memory: 2.2 MB
impl Solution {
    pub fn number_of_steps (num: i32) -> i32 {
        (31 + std::cmp::max(1, num.count_ones()) - num.leading_zeros()) as i32
    }
}