Golang 58ms concise solution


  • 0

    Please let me know if there is room to optimize this code.

    func isPalindrome(x int) bool {
        if x < 0 {
            return false
        } else if x <= 9 {
            return true
        } else if x % 10 == 0 {
            return false
        }
        
        var y int
        for x > y {
            r := x % 10
            x = x / 10
            y = y * 10 + r
            
            if x == y || x / 10 == y {
                return true
            }
        }
        return false
    }
    

Log in to reply
 

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