Skip to content

Commit cb0c4f4

Browse files
committed
feat: update solutions to leetcode problem: No.0009
1 parent a025ba4 commit cb0c4f4

File tree

4 files changed

+53
-21
lines changed

4 files changed

+53
-21
lines changed

solution/0000-0099/0009.Palindrome Number/README.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,33 @@
4242
<!-- 这里可写当前语言的特殊实现逻辑 -->
4343

4444
```python
45-
45+
class Solution:
46+
def isPalindrome(self, x: int) -> bool:
47+
if x < 0:
48+
return False
49+
y, t = 0, x
50+
while t:
51+
y = y * 10 + t % 10
52+
t //= 10
53+
return x == y
4654
```
4755

4856
### **Java**
4957

5058
<!-- 这里可写当前语言的特殊实现逻辑 -->
5159

5260
```java
53-
61+
class Solution {
62+
public boolean isPalindrome(int x) {
63+
if (x < 0) return false;
64+
int y = 0, t = x;
65+
while (t != 0) {
66+
y = y * 10 + t % 10;
67+
t /= 10;
68+
}
69+
return x == y;
70+
}
71+
}
5472
```
5573

5674
### **...**

solution/0000-0099/0009.Palindrome Number/README_EN.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,31 @@
5151
### **Python3**
5252

5353
```python
54-
54+
class Solution:
55+
def isPalindrome(self, x: int) -> bool:
56+
if x < 0:
57+
return False
58+
y, t = 0, x
59+
while t:
60+
y = y * 10 + t % 10
61+
t //= 10
62+
return x == y
5563
```
5664

5765
### **Java**
5866

5967
```java
60-
68+
class Solution {
69+
public boolean isPalindrome(int x) {
70+
if (x < 0) return false;
71+
int y = 0, t = x;
72+
while (t != 0) {
73+
y = y * 10 + t % 10;
74+
t /= 10;
75+
}
76+
return x == y;
77+
}
78+
}
6179
```
6280

6381
### **...**
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
class Solution {
22
public boolean isPalindrome(int x) {
3-
if (x < 0) {
4-
return false;
3+
if (x < 0) return false;
4+
int y = 0, t = x;
5+
while (t != 0) {
6+
y = y * 10 + t % 10;
7+
t /= 10;
58
}
6-
int res = 0;
7-
int y = x;
8-
while (y != 0) {
9-
res = res * 10 + y % 10;
10-
y /= 10;
11-
}
12-
return res == x;
9+
return x == y;
1310
}
1411
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
class Solution:
2-
def isPalindrome(self, num):
3-
"""
4-
:type num: int
5-
:rtype: bool
6-
"""
7-
if num < 0:
2+
def isPalindrome(self, x: int) -> bool:
3+
if x < 0:
84
return False
9-
10-
return str(num) == str(num)[::-1]
5+
y, t = 0, x
6+
while t:
7+
y = y * 10 + t % 10
8+
t //= 10
9+
return x == y

0 commit comments

Comments
 (0)