剑指offer-链表反转

题目描述

输入一个链表,反转链表后,输出链表的所有元素。大概思路流程如下图:
public class Solution {
    public ListNode ReverseList(ListNode head) {
         ListNode newHead=null;
         ListNode next=null;
         ListNode p=head;
        if(head==null)
            return null;
        while(p!=null){
            next=p.next;
            p.next=newHead;
            newHead=p;
            p=next;
        }
        return newHead;
}




猜你喜欢

转载自blog.csdn.net/m0_37443464/article/details/79873092
今日推荐