Skip to content

Commit 532418d

Browse files
committed
add 1342
1 parent 6220492 commit 532418d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "S1342-number-of-steps-to-reduce-a-number-to-zero"
3+
version = "0.1.0"
4+
authors = ["Xargin <cao1988228@163.com>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fn main() {
2+
dbg!(Solution::number_of_steps(14));
3+
}
4+
5+
struct Solution;
6+
7+
impl Solution {
8+
pub fn number_of_steps (num: i32) -> i32 {
9+
(num.count_ones() * 2 - 1 + num.count_zeros() - num.leading_zeros()) as i32
10+
}
11+
}

0 commit comments

Comments
 (0)