Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a819621

Browse files
committed
fix leetcode 0009 with go
1 parent 24047be commit a819621

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 9. 回文数
2+
3+
## 链接
4+
https://leetcode-cn.com/problems/palindrome-number/
5+
6+
## 难度
7+
简单
8+
9+
## 描述
10+
判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。
11+
12+
示例 1:
13+
```text
14+
输入: 121
15+
输出: true
16+
```
17+
示例 2:
18+
```text
19+
输入: -121
20+
输出: false
21+
解释: 从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。
22+
```
23+
示例 3:
24+
```text
25+
输入: 10
26+
输出: false
27+
解释: 从右向左读, 为 01 。因此它不是一个回文数。
28+
```
29+
## 思路
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package _009_Palindrome_Number
2+
3+
import (
4+
"strconv"
5+
)
6+
7+
func isPalindrome(x int) bool {
8+
s := strconv.Itoa(x)
9+
return isPalindromeByIndex(s, 0, len(s)-1)
10+
}
11+
12+
func isPalindromeByIndex(s string, start int, end int) bool {
13+
for start < end && s[start] == s[end] {
14+
start++
15+
end--
16+
}
17+
return start >= end
18+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /