public ListNode reverseList(ListNode head) {
            ListNode reversed = null;
            ListNode p = head;
            while (p != null) {
                ListNode temp = p.next;
                p.next = reversed;
                reversed = p;
                p = temp;
            }
            return reversed;
        }