Simple Swift Solution


  • 0
    Y
    func checkPerfectNumber(_ num: Int) -> Bool {
            if num <= 1 { return false }
            var factor = 1
            var i = 2
            while i <= num/i{
                if num % i == 0{ factor = factor + i + num/i } 
                i += 1
            }
            return factor == num ? true : false
      }

Log in to reply
 

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