Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. # Definition for singly-linked list.
  2. # class ListNode:
  3. # def __init__(self, x):
  4. # self.val = x
  5. # self.next = None
  6.  
  7. class Solution:
  8. def isPalindrome(self, head: ListNode) -> bool:
  9.  
  10. num1 = 0
  11. num2 = 0
  12. if head:
  13. num1 = head.val
  14. num2 = head.val
  15.  
  16. cur = head.next
  17. i = 1
  18. while (cur):
  19. num1 = num1 + (cur.val * (10 ** i))
  20. num2 = (num2 * 10) + cur.val
  21. i += 1
  22. cur = cur.next
  23.  
  24. if num1 == num2:
  25. return True
  26. else:
  27. return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement