Solution in Swift


  • 0
    J
    class Solution {
        func reverse(_ x: Int) -> Int {
            var remain = x
            var result = 0
            while remain != 0 {
                result *= 10
                result += remain % 10
                remain /= 10
                if result < Int32.min || result > Int32.max {
                    return 0
                }
            }
            return result
        }
    }
    

Log in to reply
 

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