<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:
        tot = head
        hare = head
        count = 1
        prev = None
        temp = head
        while(temp.next!=None):
            count=count+1
            temp = temp.next
            
        while hare!=None and hare.next!=None:
            prev = tot
            tot=tot.next
            hare = hare.next.next
            # count +=1
        # print("prev: ",prev)
        # print("tot: ",tot)
        # print("hare: ",hare)
        print("count: ",count)
        # for 1221 we need tot [21]
        # even for 12 we need tot [2]
        # 2ndHBegin =  tot
        # firstHEnd = prev 
        # in both case we can see its even count 
        
        # TODO conditioin based on even or odd.
        
        # [4,3,4]
        # incase of odd we need to ignore tot.val and do next half till end 
        # 2ndHBegin =  tot.next and end till None [4,None] or simply hare
        # firstHEnd = prev and till None(reversed) and prev to None [4,None]

        # reverse 1st half

        prev = None
        curr = head
        front = None
        while(curr != tot):
            front = curr.next
            curr.next = prev
            prev = curr
            curr = front

        # print("left reversed List: ",prev)
        # print("RIght forward List: ",tot)

        if count%2 !=0:
            tot = tot.next

        while tot!=None:
            if tot.val != prev.val:
                return False
            tot = tot.next
            prev = prev.next

        return True
20761