Files
LeetCode-Go/leetcode/0009.Palindrome-Number/9. Palindrome Number.go
2020-08-12 20:12:33 +08:00

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
}