您的位置:首页 > 编程语言 > C语言/C++

leetcode_c++:链表:Reverse Linked Lis(206)

2016-07-18 16:21 375 查看
Reverse Linked Lis

class Solution {
public:
ListNode* reverseList(ListNode* head) {
if(head==NULL||head->next==NULL)
return head;

ListNode* dummy=new ListNode(-1);
dummy->next=head;

ListNode* prev=head,*cur=head->next;

while(cur){
prev->next=cur->next;
cur->next=dummy->next;
dummy->next=cur;
cur=prev->next;
}
return dummy->next;

}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: