-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution9.go
More file actions
33 lines (29 loc) · 716 Bytes
/
Copy pathsolution9.go
File metadata and controls
33 lines (29 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package solution9
import (
"strconv"
)
// ============================================================================
// 9. Palindrome Number
// URL: https://leetcode.com/problems/palindrome-number/
// ============================================================================
/*
goos: linux
goarch: amd64
pkg: GoLeetCode/solutions/9---Palindrome-Number
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
Benchmark_isPalindrome
Benchmark_isPalindrome-24 48831478 20.94 ns/op 3 B/op 1 allocs/op
PASS
*/
func isPalindrome(x int) bool {
if x < 0 {
return false
}
s := strconv.Itoa(x)
for i := 0; i < len(s); i++ {
if s[i] != s[len(s)-i-1] {
return false
}
}
return true
}