LXYlxy666

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* reverseList(struct ListNode* head) {
    int i=0;
    struct ListNode* p[5000];
    if(head==NULL) return head;
    while(head!=NULL){
        p[i++]=head;
        head=head->next;
    }
    i=i-1;

    head=p[i];
    for(;i>0;i--){
        p[i]->next=p[i-1];
    }
    p[0]->next=NULL;
    return head;
}

  需要注意的是 n1 的下一个节点必须指向 ∅。如果忽略了这一点,链表中可能会产生环。

即链表最后一个节点必须需指向NULL;

posted on 2025-09-06 23:07  printf("赖狒狒");  阅读(4)  评论(0)    收藏  举报