LeetCode:206. Reverse Linked List
2017-03-20 19:44
369 查看
Reverse a singly linked list.
AC:
/**
* 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* next=NULL;
while(head!=NULL){
next=head->next;
head->next=pre;
pre=head;
head=next;
}
return pre;
}
};
AC:
/**
* 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* next=NULL;
while(head!=NULL){
next=head->next;
head->next=pre;
pre=head;
head=next;
}
return pre;
}
};
相关文章推荐
- Leetcode-206. Reverse Linked List
- LeetCode-206. Reverse Linked List
- LeetCode 206. Reverse Linked List
- LeetCode 206. Reverse Linked List
- [LeetCode] 206. Reverse Linked List
- LeetCode 206. Reverse Linked List
- 【LeetCode】206. Reverse Linked List
- 206. Reverse Linked List leetcode list
- [LeetCode]206. Reverse Linked List&92. Reverse Linked List II
- Leetcode 206. Reverse Linked List
- LeetCode 206. Reverse Linked List
- Leetcode题解 206. Reverse Linked List
- Leetcode 206. Reverse Linked List
- Leetcode206. Reverse Linked List
- [leetcode] 206.Reverse Linked List
- 【leetcode】206. Reverse Linked List
- 迭代和递归 - leetcode 206. Reverse Linked List
- LeetCode 206. Reverse Linked List
- [LeetCode] 206. Reverse Linked List
- leetcode 每日一题 206. Reverse Linked List