输入一个链表,反转链表后,输出新链表的表头。
public class Solution { public ListNode ReverseList(ListNode head) { ListNode qHead=null;//翻转后的头结点 if(head==null || head.next == null){ return head; } ListNode p = head; while (p!=null){ ListNode nextNode = p.next;//暂存 p.next = qHead; qHead = p; p = nextNode; } return qHead; } }

浙公网安备 33010602011771号