Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update 009_Palindrome_Number.py
  • Loading branch information
peterhuang1kimo authored Oct 6, 2020
commit c9a4733b1ba44fcd9fb47f08a88ee967977ef487
17 changes: 7 additions & 10 deletions python/009_Palindrome_Number.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ class Solution(object):
def isPalindrome(self, x):
if x < 0:
return False
ls = 0
ls = len(str(x))
tmp = x
while tmp != 0:
ls += 1
tmp = tmp // 10
tmp = x
for i in range(ls/2):
right = tmp % 10
print((int(ls/2)))
for i in range(int(ls/2)):
right = int(tmp % 10)
left = tmp / (10 ** (ls - 2 * i - 1))
left = left % 10
# print left, right
left = int(left % 10)
print (left, right)
if left != right:
return False
tmp = tmp // 10
Expand Down Expand Up @@ -62,4 +59,4 @@ def isPalindrome(self, x):
if __name__ == '__main__':
# begin
s = Solution()
print s.isPalindrome(1001)
print s.isPalindrome(1001)