2
public boolean isPalindrome(ListNode head) {4
ListNode mid = getMiddle(head);5
ListNode headSecond = reverse(mid);6
ListNode reverseHead = headSecond;8
while (head != null && headSecond != null) {9
if (head.val != headSecond.val) {13
headSecond = headSecond.next;17
return head == null || headSecond == null;20
public ListNode reverse(ListNode head) {21
if (head == null) return head;23
ListNode present = head;24
ListNode next = head.next;25
while (present != null) {29
if (next != null) next = next.next;34
public ListNode getMiddle(ListNode head) {37
while (temp != null) {43
for (int i = 0; i < mid; i++) {