File tree Expand file tree Collapse file tree 1 file changed +48
-5
lines changed Expand file tree Collapse file tree 1 file changed +48
-5
lines changed Original file line number Diff line number Diff line change 1
- ### 9. Palindrome Number
1
+ # 9. Palindrome Number 回文数
2
2
3
- 题目:
4
- < https://leetcode.com/problems/palindrome-number/ >
3
+ ## 题目
5
4
6
- 难度:
7
- Medium
5
+ * https://leetcode.com/problems/palindrome-number
6
+ * https://leetcode-cn.com/problems/palindrome-number/description
8
7
8
+ ```
9
+ 判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。
10
+
11
+ 示例 1:
12
+
13
+ 输入: 121
14
+ 输出: true
15
+ 示例 2:
16
+
17
+ 输入: -121
18
+ 输出: false
19
+ 解释: 从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。
20
+ 示例 3:
21
+
22
+ 输入: 10
23
+ 输出: false
24
+ 解释: 从右向左读, 为 01 。因此它不是一个回文数。
25
+ 进阶:
26
+
27
+ 你能不将整数转为字符串来解决这个问题吗?
28
+ ```
29
+
30
+ ## 难度:Medium
31
+
32
+ > 思路1
9
33
10
34
- 首先负数肯定不是palindrome
11
35
- 其次如果一个数字是一个正数,并且能被我0整除那它肯定也不是palindrome
@@ -29,3 +53,22 @@ class Solution(object):
29
53
30
54
```
31
55
56
+ > 思路2
57
+
58
+ * 排除小于0的数
59
+ * 通过字符串进行反转,对比数字是否相等就行
60
+
61
+ ``` python
62
+ class Solution :
63
+ def isPalindrome (self , x ):
64
+ """
65
+ :type x: int
66
+ :rtype: bool
67
+ """
68
+ if x < 0 :
69
+ return False
70
+ elif x != int (str (x)[::- 1 ]):
71
+ return False
72
+ else :
73
+ return True
74
+ ```
You can’t perform that action at this time.
0 commit comments