Leetcode 142. Linked List Cycle II (Medium) (cpp)
来源:互联网 发布:淘宝客独家是什么意思 编辑:程序博客网 时间:2024/06/04 18:43
Leetcode 142. Linked List Cycle II (Medium) (cpp)
Tag: Linked List, Two Pointers
Difficulty: Medium
/*142. Linked List Cycle II (Medium)Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up:Can you solve it without using extra space?*//** * 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) { if(head == NULL || head -> next == NULL) { return NULL; } ListNode *s = head, *f = head; while (f != NULL && f -> next != NULL) { s = s -> next; f = f -> next -> next; if (s == f) break; } if (s != f) return NULL; while (head != s) { head = head -> next; s = s -> next; } return head; }};
0 0
- Leetcode 142. Linked List Cycle II (Medium) (cpp)
- 142.leetcode Linked List Cycle II(medium)[有环链表]
- [Leetcode 141 & 142, medium] Linked List Cycle (I and II)
- [LeetCode]141. Linked List Cycle【&142. Linked List Cycle II】
- leetcode--141. Linked List Cycle&&142. Linked List Cycle II
- LeetCode 141. Linked List Cycle && 142. Linked List Cycle II
- 142. Linked List Cycle II leetcode list
- Leetcode 92. Reverse Linked List II (Medium) (cpp)
- leetcode 日经贴,Cpp code -Linked List Cycle II
- LeetCode 142. Linked List Cycle II
- [LeetCode]142.Linked List Cycle II
- [leetcode] 142.Linked List Cycle II
- [leetcode] 142. Linked List Cycle II
- leetcode 142. Linked List Cycle II
- [Leetcode]142. Linked List Cycle II @python
- [LeetCode]142. Linked List Cycle II
- 142. Linked List Cycle II LeetCode
- LeetCode:142. Linked List Cycle II
- PHP延迟绑定练习
- 项目中XA Transaction应用
- UVA 10200 (欧拉定理打表)
- Android中接口回调、方法回调
- 如何重启MySQL服务
- Leetcode 142. Linked List Cycle II (Medium) (cpp)
- jvm 类初始化的条件
- eclipse连接数据库sql server 2008
- 51nod oj 1050 循环数组最大子段和 【DP】
- js中的preventDefault与stopPropagation详解
- PHP接口的概念跟接口语言与接口的应用场景
- skip-grant-tables:非常有用的mysql启动参数
- 价格区间选择案例 吸附功能
- 设计模式之单例模式