<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a </em><span data-keyword="palindrome-sequence"><em>palindrome</em></span><em> or </em><code>false</code><em> otherwise</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/03/pal1linked-list.jpg" style="width: 422px; height: 62px;" />
<pre>
<strong>Input:</strong> head = [1,2,2,1]
<strong>Output:</strong> true
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/03/pal2linked-list.jpg" style="width: 182px; height: 62px;" />
<pre>
<strong>Input:</strong> head = [1,2]
<strong>Output:</strong> false
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li>The number of nodes in the list is in the range <code>[1, 10<sup>5</sup>]</code>.</li>
	<li><code>0 &lt;= Node.val &lt;= 9</code></li>
</ul>

<p>&nbsp;</p>
<strong>Follow up:</strong> Could you do it in <code>O(n)</code> time and <code>O(1)</code> space?
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next









# DONT REDO _ just look at alternate solution at bottom
class Solution:
    def isPalindrome(self, head: Optional[ListNode]) -> bool:

        start = head

        prev = None
        curr = head
        res = []

        while curr:
            res.append(curr.val) 
            next_node = curr.next
            curr.next = prev
            prev = curr
            curr = next_node
        
        curr = prev
        res2 = []
        while curr: 
            res2.append(curr.val)
            curr = curr.next
        
        return res == res2


# class Solution:
#     def reverse(self, head: ListNode) -> ListNode:
#         prev = None
#         curr = head
#         while curr:
#             next_temp = curr.next
#             curr.next = prev
#             prev = curr
#             curr = next_temp
#         return prev

#     def isPalindrome(self, head: Optional[ListNode]) -> bool:
#         slow = head
#         fast = head
#         while fast and fast.next:
#             slow = slow.next
#             fast = fast.next.next
#         rev = self.reverse(slow)
#         while rev:
#             if head.val != rev.val:
#                 return False
#             head = head.next
#             rev = rev.next
#         return True
        
21033