142. Linked List Cycle II(java)
来源:互联网 发布:linux批量ping的命令 编辑:程序博客网 时间:2024/05/29 19:39
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.
public class Solution { public ListNode detectCycle(ListNode head) { ListNode fast = head; ListNode slow = head; while (true) { if (fast == null || fast.next == null) return null; slow = slow.next; fast = fast.next.next; if (fast == slow) break; } //if(head==null||head.next==null||head.next.next==null) return null ; //ListNode fast = head; //ListNode slow = head; //while(fast.next!=null&&fast.next.next!=null){ //fast=fast.next.next; //slow=slow.next; //if (fast==slow) break;} slow = head; while(slow!=head){ slow=slow.next; fast=fast.next; } return slow; }}
阅读全文
0 0
- [LeetCode] 142. Linked List Cycle II java
- 142. Linked List Cycle II(java)
- Linked List Cycle II Java
- Linked List Cycle II (Java)
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- xml以及json 和Java对象的相互转化
- adb 获取Android手机信息命令
- ORB特征点检测
- Android学习-- 基于位置的服务 LBS(基于百度地图Android SDK)--定位SDK
- Linux下批处理文件编写
- 142. Linked List Cycle II(java)
- Centos6.8安装docker
- css属性兼容
- 图像的腐蚀与膨胀算法原理
- 链表翻转(给出一个链表和一个数k,比如链表1→2→3→4→5→6,k=2,翻转后2→1→4→3→6→5)
- AtomicInteger简介
- filebeat
- 关于iOS 键盘只能输入字母和数字
- mysql 1045 错误