Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1cd8f3a

Browse files
committed
feat: 0009.leetcode-isPalindrome-回文数
1 parent 9c2fc63 commit 1cd8f3a

File tree

1 file changed

+15
-1
lines changed
  • 0009.leetcode-isPalindrome-回文数

1 file changed

+15
-1
lines changed

0009.leetcode-isPalindrome-回文数/main.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package main
66

77
import (
88
"fmt"
9+
"strconv"
910
)
1011

1112
func main() {
@@ -14,5 +15,18 @@ func main() {
1415
}
1516

1617
func isPalindrome(x int) bool {
17-
18+
if x < 0 {
19+
return false
20+
}
21+
if x < 10 {
22+
return true
23+
}
24+
s := strconv.Itoa(x)
25+
length := len(s)
26+
for i := 0; i <= length/2; i++ {
27+
if s[i] != s[length-1-i] {
28+
return false
29+
}
30+
}
31+
return true
1832
}

0 commit comments

Comments
 (0)