判断链表中是否有环
public class Solution {
public boolean hasCycle(ListNode head) {
ListNode head1=head;
ListNode head2=head;
if(head==null){
return false;
}
while(head1!=null&&head1.next!=null){
head2=head2.next;
head1=head1.next.next;
if(head1==head2)
return true;
}
return false;
}
}
public boolean hasCycle(ListNode head) {
ListNode head1=head;
ListNode head2=head;
if(head==null){
return false;
}
while(head1!=null&&head1.next!=null){
head2=head2.next;
head1=head1.next.next;
if(head1==head2)
return true;
}
return false;
}
}
全部评论
相关推荐
05-12 17:00
门头沟学院 Java king122:你的项目描述至少要分点呀,要实习的话,你的描述可以使用什么技术,实现了什么难点,达成了哪些数字指标,这个数字指标尽量是真实的,这样面试应该会多很多,就这样自己包装一下,包装不好可以找我,我有几个大厂最近做过的实习项目也可以包装一下
点赞 评论 收藏
分享