Skip to content

Commit 2de74e8

Browse files
committed
Sync LeetCode submission - Perfect Number (rust)
1 parent f467035 commit 2de74e8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

problems/perfect_number/solution.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
impl Solution {
2+
pub fn check_perfect_number(num: i32) -> bool {
3+
num != 1 && get_divisors(num) == 2 * num
4+
}
5+
}
6+
7+
fn get_divisors(num: i32) -> i32 {
8+
let mut acc = 0;
9+
for i in 1..((num as f64).sqrt() + 1.0) as i32 {
10+
if num % i == 0 {
11+
acc += i;
12+
acc += num / i;
13+
}
14+
}
15+
acc
16+
}

0 commit comments

Comments
 (0)