private ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode newhead = null;
        ListNode p = head;
        while (p != null) {
            ListNode q = p.next;
            p.next = newhead;
            newhead = p;
            p = q;
        }
        return newhead;
    }