Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Definition for singly-linked list.
- # class ListNode:
- # def __init__(self, x):
- # self.val = x
- # self.next = None
- class Solution:
- def isPalindrome(self, head: ListNode) -> bool:
- num1 = 0
- num2 = 0
- if head:
- num1 = head.val
- num2 = head.val
- cur = head.next
- i = 1
- while (cur):
- num1 = num1 + (cur.val * (10 ** i))
- num2 = (num2 * 10) + cur.val
- i += 1
- cur = cur.next
- if num1 == num2:
- return True
- else:
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement