赞
踩
题目描述与链接
题目思路解析
AC代码
public class Solution { public ListNode detectCycle(ListNode head) { ListNode fast=head; ListNode slow=head; //第一次相遇 while(true){ if(fast==null||fast.next==null){ return null; } fast=fast.next.next; slow=slow.next; if(fast==slow) { break; } } fast=head; while(slow!=fast){ slow=slow.next; fast=fast.next; } return fast; } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。