Palindrome : 회문(거꾸로 읽어도 제대로 읽는 것과 같은 문장이나 낱말, 숫자, 문자열)
Given the head of a singly linked list, return true if it is a palindrome or false otherwise.

Input: head = [1,2,2,1]
Output: true

Input: head = [1,2]
Output: false
Follow up: Could you do it in O(n) time and O(1) 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:
fast, slow, prev = head, head, None
while fast and fast.next:
slow, fast = slow.next, fast.next.next
# prev, slow, prev.next = slow, slow.next, None
# reverse rest of the list
while slow:
next_node = slow.next
slow.next = prev
prev = slow
slow = next_node
fast, slow = head, prev
while slow:
if fast.val!= slow.val: return False
fast, slow = fast.next, slow.next
return True
