<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
class Solution:
    def isPalindrome(self, head: Optional[ListNode]) -> bool:
        middleNode = self.findMiddleNode(head)
        middleNode = self.reverseLinkedList(middleNode)
        return self.checkIfPallindrome(head, middleNode)
    
    def findMiddleNode(self, head: Optional[ListNode]) -> Optional[ListNode]:
        slow_ptr = fast_ptr = head

        while fast_ptr and fast_ptr.next:
            slow_ptr = slow_ptr.next
            fast_ptr = fast_ptr.next.next

        return slow_ptr
    
    def reverseLinkedList(self, head: Optional[ListNode]) -> Optional[ListNode]:
        current_ptr = head

        while current_ptr and current_ptr.next:
            next_ptr = current_ptr.next
            current_ptr.next = next_ptr.next
            next_ptr.next = head
            head = next_ptr

        return head

    def checkIfPallindrome(self, head_1: Optional[ListNode], head_2: Optional[ListNode]) -> bool:
        while head_1 and head_2:
            print(head_1.val, head_2.val)
            if head_1.val != head_2.val:
                return False
            head_1 = head_1.next
            head_2 = head_2.next

        return True
        
27000