3.go 245 B

123456789101112
  1. package main
  2. func isPalindrome(x int) bool {
  3. // -1 --> -1-, impossible
  4. if x < 0 { return false }
  5. // judge if reverse(x) == x
  6. res, y := 0, x
  7. for ; x != 0; x /= 10 {
  8. res = res * 10 + x % 10
  9. }
  10. return res == y
  11. }