LeetCode之Linked List Cycle II
2013-12-26 11:42
411 查看
http://oj.leetcode.com/problems/linked-list-cycle-ii/
还是给定一个链表,查看是不是有环,有环的话返回 环的起始节点。
为了 without using extra space, 遍历某节点后更改val用以表明该节点已遍历过
还是给定一个链表,查看是不是有环,有环的话返回 环的起始节点。
为了 without using extra space, 遍历某节点后更改val用以表明该节点已遍历过
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *detectCycle(ListNode *head) { while(head) { if(head->next == NULL) break; if(head->val == 11111) { return head; } head->val = 11111; head = head->next; } return NULL; } };
相关文章推荐
- Linked List Cycle II -LeetCode
- 开始刷leetcode day12:Linked List Cycle II
- LeetCode Linked List Cycle II
- Leetcode: Linked List Cycle II
- 63_leetcode_Linked List Cycle II
- LeetCode:Linked List Cycle II
- leetcode笔记--Linked List Cycle II
- LeetCode:Linked List Cycle II
- [Leetcode][python]Linked List Cycle/Linked List Cycle II
- LeetCode——Linked List Cycle II
- (leetcode)Linked List Cycle II
- leetcode 日经贴,Cpp code -Linked List Cycle II
- LeetCode Linked List Cycle && Linked List CycleII
- leetcode:linked_list_cycle_II
- Linked List Cycle II -- leetcode
- LeetCode刷题:Linked List Cycle 及其进阶Linked List Cycle II
- LeetCode 142: Linked List Cycle II
- leetcode Linked List Cycle II
- leetcode: Linked List Cycle II
- 【LeetCode】Linked List Cycle II