Skip to content

Instantly share code, notes, and snippets.

@kuntalchandra
Created April 1, 2021 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuntalchandra/9a8d153549901e5f816cb50e1edc1d31 to your computer and use it in GitHub Desktop.
Save kuntalchandra/9a8d153549901e5f816cb50e1edc1d31 to your computer and use it in GitHub Desktop.
Given the head of a singly linked list, return true if it is a palindrome
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def isPalindrome(self, head: ListNode) -> bool:
numbers = []
sentinel = head
while sentinel:
numbers.append(sentinel.val)
sentinel = sentinel.next
return numbers == numbers[::-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment