mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
21 lines
269 B
Go
21 lines
269 B
Go
package leetcode
|
|
|
|
import "strconv"
|
|
|
|
func isPalindrome(x int) bool {
|
|
if x < 0 {
|
|
return false
|
|
}
|
|
if x < 10 {
|
|
return true
|
|
}
|
|
s := strconv.Itoa(x)
|
|
length := len(s)
|
|
for i := 0; i <= length/2; i++ {
|
|
if s[i] != s[length-1-i] {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|