My 3 Lines Swift Solution


  • 0
    Y
    func reverse(_ x: Int) -> Int {
            let input = abs(x)
            if Int(String(String(input).characters.reversed()))! > 2147483649 { return 0 }
            return x >= 0 ? Int(String(String(input).characters.reversed()))! : Int(String(String(input).characters.reversed()))! * (-1)
            // Int(Int32.max) will not be the same as the Expected answer
        }

Log in to reply
 

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