• ㊗️
• 大家
• offer
• 多多！

## Problem

Given a singly linked list, determine if it is a palindrome.

Example 1:

Input: 1->2
Output: false


Example 2:

Input: 1->2->2->1
Output: true


## Code

class Solution {
return true;
}

ListNode midNext = reverse(mid.next);

while(midNext != null){
midNext = midNext.next;
} else {
return false;
}
}

return true;
}

ListNode dummy = new ListNode(-1);

ListNode slow = dummy;
ListNode fast = dummy;

while(fast != null && fast.next != null){
slow = slow.next;
fast = fast.next.next;
}

return slow;
}

ListNode prev = null;

}

return prev;
}
}

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
def getMid(self, head: ListNode) -> ListNode:
dummy = ListNode(-1)

slow = dummy
fast = dummy

while fast.next and fast.next.next:
slow = slow.next
fast = fast.next.next

return slow

def reverse(self, head: ListNode) -> ListNode:
prev = None

return prev

def isPalindrome(self, head: ListNode) -> bool:
return True