package leetcode; public class DetectCycle {
public ListNode detectCycle(ListNode head) {
ListNode s=head;
ListNode f=head;
while(f!=null&&f.next!=null){
s=s.next;
f=f.next.next;
if(s==f){
break;
}
}
if(f==null||f.next==null)
return null;
s=head;
while(s!=f){
s=s.next;
f=f.next;
}
return s;
}
}
相关文章
- 03-05Codeforces 1206 D - Shortest Cycle
- 03-05UFUN函数 UF_ATTR函数(UF_ATTR_cycle )
- 03-05NX二次开发-UFUN遍历函数UF_OBJ_cycle_objs_in_part
- 03-05NX二次开发-UFUN遍历函数UF_OBJ_cycle_all
- 03-05[React] Detect user activity with a custom useIdle React Hook
- 03-05fatal: unable to auto-detect email address (got 'tim@newton.(none)')的解决方法
- 03-05TensorFlow object_detect 修改配置文件进行数据增强处理
- 03-05Python chardet.detect卡、效率低、非常慢等
- 03-05leetcode-006 detect cycle
- 03-05[LeetCode] 141. Linked List Cycle 单链表判圆算法