Skip to content

Commit 2970d03

Browse files
committed
solved: 476. Number Complement
Signed-off-by: rajput-hemant <[email protected]>
1 parent 0b46607 commit 2970d03

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
impl Solution {
2+
pub fn find_complement(num: i32) -> i32 {
3+
let mut res = String::new();
4+
5+
for ch in format!("{:b}", num).chars() {
6+
if ch == '0' {
7+
res += "1";
8+
} else {
9+
res += "0";
10+
}
11+
}
12+
13+
i32::from_str_radix(&res, 2).unwrap()
14+
}
15+
}

0 commit comments

Comments
 (0)