反转链表

class Solution {
    public ListNode reverseList(ListNode head) {
       ListNode pre=null;
       ListNode cur=head;
       ListNode temp=null;
       while(cur!=null)
       {
           temp=cur.next;
           cur.next=pre;
           pre=cur;
           cur=temp;
       }
       return pre;
    }
}
posted @ 2021-11-29 20:44  一刹流云散  阅读(6)  评论(0编辑  收藏  举报