Two pointer, Java solution.


  • 1

    class Solution {
    public boolean checkPerfectNumber(int num) {
    if (num == 1) {
    return false;
    }

        int result = 1;
        int end = num;
        
        
        for (int i = 2; i < end; i++) {
            if (num % i == 0) {
                result += i;
                end = num / i;
                result += end;
            }
        }
        return result == num;
    }
    

    }


Log in to reply
 

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