Simple Swift Solution


  • 0
    Y
    func isUgly(_ num: Int) -> Bool {
            var input = num
            if input <= 0 { return false }
            while input % 5 == 0 { input /= 5 }
            while input % 3 == 0 { input /= 3 }
            while input % 2 == 0 { input /= 2 }
            return input == 1 ? true : false
    }

Log in to reply
 

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