也就是LeetCode25里用到了反转子链表的方法,只不过这次直接反转整个链表。头插法就能解决了
class Solution { public ListNode reverseList(ListNode head) { ListNode t = new ListNode(-1); t.next = null; ListNode a = head; ListNode b = null; while(a!=null){ b = a.next; a.next = t.next; t.next = a; a = b; } return t.next; } }