-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path9_Palindrome Number.py
More file actions
46 lines (40 loc) · 932 Bytes
/
9_Palindrome Number.py
File metadata and controls
46 lines (40 loc) · 932 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
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 31 17:16:14 2019
@author: leiya
"""
'''
updated: 0630
注意最后比较的是res和之前的值
'''
class Solution:
def isPalindrome(self, x: int) -> bool:
if x < 0:
return False
res = 0
newx = x
while newx != 0:
temp = newx % 10
res = 10*res + temp
newx = newx // 10
return res == x
class Solution:
def isPalindrome(self, x: int) -> bool:
if str(x) == str(x)[::-1]:
return True
else:
return False
class Solution:
def isPalindrome(self, x: int) -> bool:
if x < 0:
return False
raw = x
result = 0
while x > 0:
a = x % 10
result = result * 10 + a
x //= 10
if result == raw:
return True
else:
return False