Swift code with reverse. Beats 100% of swift submissions [125ms]


  • 0
    D
    class Solution {
    func isPalindrome(_ x: Int) -> Bool {
        var xVal1: Int = x
        var r: Int = 0
        var output: Bool = false
        if x < 0  { return false }
        while xVal1 != 0 {
            r = (10 * r) + (xVal1 % 10)
            xVal1 /= 10
        }
        if r > Int(Int32.max) || r < Int(Int32.min) { return false }
        if (r * 1 == x) { return true }
        return output
        }
    }
    

Log in to reply
 

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