[leetcode 142]Linked List Cycle II
来源:互联网 发布:淘宝卖家旺旺名字大全 编辑:程序博客网 时间:2024/05/17 04:36
Given a linked list, return the node where the cycle begins. If there is no cycle, return null
.
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) { return NULL; } auto slow = head; auto fast = head; while (fast && fast->next) { slow = slow->next; fast = fast->next->next; if (slow == fast) { auto slow2 = head; while (slow2 != slow) { slow = slow->next; slow2 = slow2->next; } return slow2; } } return NULL; }};
0 0
- LeetCode.142(141) Linked List Cycle && Linked List Cycle (II)
- LeetCode 142 Linked List Cycle II
- LeetCode 142 Linked List Cycle II
- LeetCode: Linked List Cycle II [142]
- [leetcode 142]Linked List Cycle II
- Leetcode NO.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
- [leetcode-142]Linked List Cycle II(c)
- leetcode 142: Linked List Cycle II
- leetCode #142 Linked List Cycle II
- Leetcode #142 Linked List Cycle II
- 142 Linked List Cycle II [Leetcode]
- 【LEETCODE】142-Linked List Cycle II
- LeetCode 142 Linked List Cycle II
- Yaw pitch roll
- Properties 盛放配置及监控变化
- ubuntu14.04 matlab2015 64bits
- vmware-ubuntu-无法上网
- 一个优化过的OC的简单冒泡排序算法
- [leetcode 142]Linked List Cycle II
- NSNotification 通知
- BIOS和CMOS的区别
- RoboGuice @Nullable a easy solution
- Lease 机制在分布式系统中的应用
- Java去空格
- Linux防火墙
- linux函数fork,vfork,clone
- 分布式系统原理