本文共 574 字,大约阅读时间需要 1 分钟。
尾插法
/*public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }}*/public class Solution { public ListNode ReverseList(ListNode head) { if(head == null) { return null; } ListNode node = head.next; ListNode tail = head; head.next = null; //尾插法 while(node != null) { ListNode tmp = node.next; node.next = tail; tail = node; node = tmp; } return tail; }}
转载地址:http://pzicn.baihongyu.com/