File tree Expand file tree Collapse file tree 1 file changed +5
-11
lines changed Expand file tree Collapse file tree 1 file changed +5
-11
lines changed Original file line number Diff line number Diff line change @@ -9,23 +9,17 @@ class Solution(object):
9
9
def isPalindrome (self , x ):
10
10
if x < 0 :
11
11
return False
12
- ls = 0
12
+ ls = len ( str ( x ))
13
13
tmp = x
14
- while tmp != 0 :
15
- ls += 1
16
- tmp = tmp // 10
17
- tmp = x
18
- for i in range (ls / 2 ):
19
- right = tmp % 10
14
+ for i in range (int (ls / 2 )):
15
+ right = int (tmp % 10 )
20
16
left = tmp / (10 ** (ls - 2 * i - 1 ))
21
- left = left % 10
22
- # print left, right
17
+ left = int (left % 10 )
23
18
if left != right :
24
19
return False
25
20
tmp = tmp // 10
26
21
return True
27
22
28
-
29
23
# def isPalindrome(self, x):
30
24
# #leetcode book
31
25
# if x < 0:
@@ -62,4 +56,4 @@ def isPalindrome(self, x):
62
56
if __name__ == '__main__' :
63
57
# begin
64
58
s = Solution ()
65
- print s .isPalindrome (1001 )
59
+ print s .isPalindrome (1001 )
You can’t perform that action at this time.
0 commit comments