Java Solution with 2 pointers


  • 0
    G
    public class Solution {
        public boolean checkPerfectNumber(int num) {
            if (num <= 1) return false;
            int low = 1, hgh = num;
            int res = -num; 
            while (low <= hgh){
                if (num % low == 0) res = res + low + hgh;
                low++;
                hgh = num / low;
            }
            return res == num;
        }
    }
    

Log in to reply
 

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