diff --git a/234-palindrome-linked-list/palindrome-linked-list.py b/234-palindrome-linked-list/palindrome-linked-list.py new file mode 100644 index 0000000..459d9e4 --- /dev/null +++ b/234-palindrome-linked-list/palindrome-linked-list.py @@ -0,0 +1,18 @@ +# 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: Optional[ListNode]) -> bool: + list_vals = [] + while head: + list_vals.append(head.val) + head = head.next + + left, right = 0, len(list_vals) - 1 + while left < right and list_vals[left] == list_vals[right]: + left += 1 + right -= 1 + return left >= right + \ No newline at end of file