自学内容网 自学内容网

反转链表 - 力扣(LeetCode)

206. 反转链表 - 力扣(LeetCode)

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* reverseList(struct ListNode* head) 
{
    if(head == NULL)
        return NULL;
    else
    {
        struct ListNode* oldhead = head;
        struct ListNode* newhead = NULL;
        while(oldhead)
        {
            struct ListNode* nextnode = oldhead->next;
            oldhead->next = newhead;
            newhead = oldhead;
            //迭代
            oldhead = nextnode;
        }
        return newhead;
    }
    
}


原文地址:https://blog.csdn.net/SikJ_2020_0_24/article/details/140648568

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!