LeetCode-206. Reverse Linked List
2017-03-02 16:59
369 查看
问题:
https://leetcode.com/problems/reverse-linked-list/?tab=Description
Reverse a singly linked list.反转一个单向链表。
参考C++代码:
https://leetcode.com/problems/reverse-linked-list/?tab=Description
Reverse a singly linked list.反转一个单向链表。
参考C++代码:
/** * 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 == NULL || head->next == NULL) return head; ListNode Result(0); ListNode *p = head; while (p) { ListNode *q = p->next; p->next = Result.next; Result.next = p; p = q; } return Result.next; } };
相关文章推荐
- 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: Python]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