LeetCode Records - Question 507 Perfect Number
class Solution {
public boolean checkPerfectNumber(int num) {
if (num == 1) {
return false;
}
int count = 1;
for (int i = 2; i <= num / 2; i++) {
int quotient = num / i;
if (i > quotient) {
break;
} else if (num % i == 0) {
if (i == quotient) {
count += i;
break;
} else {
count += i;
count += quotient;
}
}
}
return num == count;
}
}
- Runtime: 3 ms (Beats: 76.10%)
- Memory: 40.25 MB (Beats: 51.15%)