Simple Solution in Java


  • 0
    E
    class Solution {
        public boolean checkPerfectNumber(int num) {
            if(num==1){
                return false;
            }
            int sum=0;
            for(int i=2;i<Math.pow(num,0.5);i++){
                if(num%i==0){
                    sum+=i+(num/i);
                }
            }
            return ++sum==num;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.