9.go 217 B

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