LeetCode 206. Reverse Linked List
2017-08-08 09:27
447 查看
206. Reverse Linked List
Description
Reverse a singly linked list.Solution
题意即将一个链表倒转。有两种方式,迭代和递归,代码如下。
// 迭代 class Solution { public: ListNode* reverseList(ListNode* head) { ListNode *pre = NULL; while (head) { ListNode *p = head->next; head->next = pre; pre = head; head = p; } return pre; } }; // 递归 class Solution { public: ListNode* reverseList(ListNode* head) { if (head == NULL || head->next == NULL) return head; ListNode *p = reverseList(head->next); head->next->next = head; head->next = NULL; return p; } };
相关文章推荐
- 【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
- 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
- [leetcode] 206. Reverse Linked List
- Leetcode题解 206. Reverse Linked List
- 【LeetCode】206. Reverse Linked List
- [leetcode: Python]206.Reverse Linked List
- LeetCode-206. Reverse Linked List
- LeetCode-206. Reverse Linked List