LeetCode 206. Reverse Linked List
2016-10-29 11:05
260 查看
描述
反转链表解决
/** * 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) return NULL; ListNode* tHead = head; while (head -> next) { ListNode* tmp = head -> next; head -> next = tmp ? tmp -> next : NULL; if (tmp) { tmp -> next = tHead; tHead = tmp; } } return tHead; } };
/** * 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* tHead = NULL; while (head) { ListNode *tmp = head; head = head -> next; tmp -> next = tHead; tHead = tmp; } return tHead; } };
相关文章推荐
- [leetcode] 206. Reverse Linked List
- Leetcode:206. Reverse Linked List
- leetCode_Add to List 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 206. Reverse Linked List
- leetcode 206. Reverse Linked List
- 【Leetcode】92. Reverse Linked List II && 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