SHARE
TWEET

Untitled

a guest Aug 23rd, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top