Solution in Swift


  • 0
    Z
    class Solution {
        func reverse(_ x: Int) -> Int {
            
            let str = String(abs(x))
            let result = Int(String(str.reversed())) ?? 0
            if result > Int32.max || result < Int32.min {
                return 0
            }
            return x < 0 ? -result : result
        }
    }
    

Log in to reply
 

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