234_Palindrome Linked List
Question
Solution 1
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def isPalindrome(self, head):
"""
:type head: ListNode
:rtype: bool
"""
if not head:
return True
# convert linked list to array
ret = []
node = head
while node:
ret.append(node.val)
node = node.next
return ret == ret[::-1]Solution 2
Last updated