public boolean isPalindrome(ListNode head) {
        if (head == null) return true;
        ListNode slow = head, fast = head;

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

        ListNode reversed = reverse(slow);
        fast = head;
        while (reversed != null && fast != null) {
            if (reversed.val != fast.val)
                return false;
            reversed = reversed.next;
            fast = fast.next;
        }
        return true;
    }