A Swift Solution


  • 0
    T
        func isUgly(num: Int) -> Bool {
            if num == 0 {
                return false
            }
            var n = num
            while(true){
                if n % 2 == 0 {
                    n = n>>1 
                }else if n % 5 == 0 {
                    n /= 5
                }else if n % 3 == 0 {
                    n /= 3
                }else if n == 1{
                    return true
                }else {
                    return false
                }
            }
            return false
        }
    

Log in to reply
 

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