Skip to content

Commit 403707d

Browse files
committed
Create 1780-check-if-number-is-a-sum-of-powers-of-three.rs
1 parent 05032c0 commit 403707d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// n 转化为3进制,只有0、1
2+
pub fn check_powers_of_three(n: i32) -> bool {
3+
let mut n = n;
4+
while n > 0 {
5+
if n % 3 == 2 { return false }
6+
n /= 3;
7+
}
8+
true
9+
}
10+
11+
fn main() {
12+
println!("{:?}", check_powers_of_three(12));
13+
}

0 commit comments

Comments
 (0)