Page tree
Skip to end of metadata
Go to start of metadata

Palindrome Linked List

Palindrome Linked List
class Solution:
    def isPalindrome(self, head: ListNode) -> bool:
        l = [head.val]
        cur = head
        while cur.next:
            cur = cur.next
            l.append(cur.val)

        for i in range(int(len(l)/2)):
            if l[i] != l[len(l)-i-1]:
                return False
            
        return True
  • No labels