LeetCode: Linked List Cycle II
来源:互联网 发布:js对联广告 编辑:程序博客网 时间:2024/06/14 05:58
思路:题目说最好不要用额外空间,促使我想利用链表节点的val,可以让其保存该节点地址,作为标记,然后开始循环搜索链表,如果发现某个节点的val值保存的是该节点的地址值(需要类型转换)说明这是以前标记过的节点,回到了远地方,所以这是循环的开始。这是出题人的不完整,这样也能过???如果让某个节点的值初始为该节点的地址值,那不玩完了!!!
class Solution {public: ListNode *detectCycle(ListNode *head) {if(head){while(head){if(head->val == int(head))return head;head->val = int(head);head = head->next;}if(!head)return NULL; }return NULL; }};
0 0
- 【LeetCode】 Linked List Cycle II
- Leetcode: Linked List Cycle II
- <Leetcode>Linked List Cycle II
- [LeetCode] Linked List Cycle II
- Leetcode: Linked List Cycle II
- LeetCode:Linked List Cycle II
- Leetcode Linked List Cycle II
- [LeetCode]Linked List Cycle II
- leetcode Linked List Cycle II
- LeetCode | Linked List Cycle II
- Leetcode: Linked List Cycle II
- [LeetCode] - Linked List Cycle II
- Leetcode: Linked List Cycle II
- LeetCode - Linked List Cycle II
- leetcode Linked List Cycle II
- Linked List Cycle II -- LeetCode
- LeetCode Linked List Cycle II
- [LeetCode] Linked List Cycle II
- POJ3130排序增量法
- asp获取当前路径语句大全
- nyoj 61 传纸条(一)双线程DP
- Asp.net课后生活(6)
- STM32F4 TIM1 7路PWM信号输出
- LeetCode: Linked List Cycle II
- Android中dip、dp、sp、pt和px的区别
- Asp.net课后总结(8)
- linux 下的select函数
- Python单元测试——深入理解unittest
- 腾讯2014实习生笔试题
- 尊重历史的人
- 泛泰 A850 4.1.2 刷第三方专用Recovery合集
- codeforces Coder-Strike 2014 Round 1 A题解题报告