首页 > 其他 > 详细

leetcode刷题34

时间:2019-09-18 23:53:19      阅读:215      评论:0      收藏:0      [点我收藏+]

今天刷的另一道题是LeetCode第141题,环形链表,这儿题也不是很难,直接快慢指针就解决了,具体地代码如下:

 public boolean hasCycle(ListNode head) {
        ListNode fast=head;
        if (head==null){
            return false;
        }
        if (head.next==head){
            return true;
        }
        while (fast.next!=null){
            if (fast.next.next==null){
                return false;
            }
            fast=fast.next.next;
            head=head.next;
            if (fast==head){
                return true;
            }            
        }
        return false;
    }

 

leetcode刷题34

原文:https://www.cnblogs.com/cquer-xjtuer-lys/p/11546065.html

(2)
(2)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!