public static boolean hasCycle(Node head){
Set<Node> seen = new HashSet<Node>();
while (head!=null){
if(!seen.add(head)){
return true;//假如失败说明有环,没换最后退出循环,null
}
head = head.getNext();
}
return false;
}
04-09
395
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交