8ms Swift solution


  • 0
    import Darwin
    
    
    func isPerfectSquare(num: Int) -> Bool {
    var val = Float(num)
    var last: Float
    repeat {
        last = val
        val = (val + Float(num)/val)/2
    }while abs(val - last) > FLT_EPSILON
    if Double(val) * Double(val) == Double(num) {
        return true
    }else {
        return false
    }
    }

Log in to reply
 

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