标签:head for while reverse span sel tco lin blog
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)
标签:head for while reverse span sel tco lin blog
原文地址:http://www.cnblogs.com/wujufengyun/p/6834187.html