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):
99 def isPalindrome (self , x ):
1010 if x < 0 :
1111 return False
12- ls = 0
12+ ls = len ( str ( x ))
1313 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 )
2016 left = tmp / (10 ** (ls - 2 * i - 1 ))
21- left = left % 10
22- # print left, right
17+ left = int (left % 10 )
2318 if left != right :
2419 return False
2520 tmp = tmp // 10
2621 return True
2722
28-
2923 # def isPalindrome(self, x):
3024 # #leetcode book
3125 # if x < 0:
@@ -62,4 +56,4 @@ def isPalindrome(self, x):
6256if __name__ == '__main__' :
6357 # begin
6458 s = Solution ()
65- print s .isPalindrome (1001 )
59+ print s .isPalindrome (1001 )
You can’t perform that action at this time.
0 commit comments