Simple 4 line Java AC solution


  • 0
    N
    public class Solution {
        public boolean checkPerfectNumber(int num) {
            int sum=1;
            for(int i=2;i<(int)(Math.sqrt(num)+1);++i)
                if(num%i==0)   sum+=i+(num/i);
            return sum==num &&num!=1;
        }
    }

Log in to reply
 

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