首页 > 学院 > 开发设计 > 正文

LeetCode 206. Reverse Linked List

2019-11-11 07:01:54
字体:
来源:转载
供稿:网友

https://leetcode.com/PRoblems/reverse-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) {        if (head == NULL) return NULL;        if (head->next == NULL) return head;                ListNode *pNode = head;        ListNode *pre = NULL;        while( pNode ) {            ListNode *pnext = pNode->next;                        pNode->next = pre;            pre = pNode;            pNode = pnext;        }        return pre;    }    };


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表