206. Reverse Linked List(LeetCode)

Posted 无惧风云

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了206. Reverse Linked List(LeetCode)相关的知识,希望对你有一定的参考价值。

Reverse a singly linked list.

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* reverseList(ListNode* head) {
    ListNode * pre=NULL;
        ListNode * current;
        while (head)
        {
            current = head;
            head = head->next;
            current->next=pre ;
            pre = current;
        }
        return pre;

    }
};

 

以上是关于206. Reverse Linked List(LeetCode)的主要内容,如果未能解决你的问题,请参考以下文章

206. Reverse Linked List

206. Reverse Linked List

206. Reverse Linked List

206. Reverse Linked List

No 206, Reverse Linked List

206. Reverse Linked List