Created
April 1, 2021 10:02
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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