class Solution {
public int pairSum(ListNode head) {
ListNode slow = head;
ListNode fast = head;
int res = Integer.MIN_VALUE;
while (fast != null && fast.next != null) {
slow = slow.next;
fast = fast.next.next;
}
ListNode nextNode, prev = null;
while (slow != null) {
nextNode = slow.next;
slow.next = prev;
prev = slow;
slow = nextNode;
}
while (prev != null) {
res = Math.max(res, head.val + prev.val);
prev = prev.next;
head = head.next;
}
return res;
}
}