Leetcode题解 142. Linked List Cycle II
来源:互联网 发布:国家药品食品数据查询 编辑:程序博客网 时间:2024/06/05 09:58
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
《程序员面试金典》原题
/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public ListNode detectCycle(ListNode head) { if(null==head) return null; ListNode fast=head; ListNode slow=head; while(fast!=null&&fast.next!=null){ fast=fast.next.next; slow=slow.next; if(fast==slow){ break; } } if(fast==null||fast.next==null){ return null; } fast=head; while(fast!=slow){ fast=fast.next; slow=slow.next; } return slow; }}
0 0
- Leetcode题解 142. Linked List Cycle II
- leetcode题解-142. Linked List Cycle II
- leetcode题解-142. Linked List Cycle II
- LeetCode Linked List Cycle & Linked List Cycle II题解
- [题解][LeetCode][Linked List Cycle II]
- LeetCode题解:Linked List Cycle 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 题解(144): Linked List Cycle II
- LeetCode题解——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
- C语言指针的函数运用和数组
- POJ1276 Cash Machine 【解法一】
- ajax、xml、json
- android studio NDK 配置及入门案例
- 处理浏览器的兼容问题之nextSibling
- Leetcode题解 142. Linked List Cycle II
- git修改启动目录和改变项目位置
- hdu5723 最小生成树+DFS(距离和,期望)
- python核心编程学习笔记-2016-07-19-03-局部变量代替模块变量
- MySQL读书笔记-MVCC多版本并发控制
- 游戏编程中的人工智能技术-神经网络入门(四)
- mysql调优
- JAVA_正则表达式(1)
- springmvc 请求参数中文乱码 ,@ResponseBody 返回中文乱码问题