llllmz

导航

206. 反转链表C

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* reverseList(struct ListNode* head) {
    if(!head) return NULL;
    struct ListNode* t=head;
    t=t->next;
    head->next=NULL;
    while(t){
        struct ListNode* tem=t;
        t=t->next;
        tem->next=head;
        head=tem;
    }
    return head;
}

结果:

posted on 2024-02-28 15:58  神奇的萝卜丝  阅读(14)  评论(0)    收藏  举报