class Solution { public ListNode reverseList(ListNode head) { ListNode dummy = new ListNode(); dummy.next = head; ListNode newDummy = new ListNode(); newDummy.next = null; while(dummy.next != null){ ListNode p = dummy.next; dummy.next = p.next; p.next = newDummy.next; newDummy.next = p; } return newDummy.next;
} }
|