美文网首页
141. 环形链表

141. 环形链表

作者: Andysys | 来源:发表于2019-12-30 22:24 被阅读0次
    public boolean hasCycle(ListNode head) {
        if (head == null || head.next == null) {
            return false;
        }
        ListNode slow = head;
        ListNode fast = head.next;
        while (slow != fast) {
            if (fast == null || fast.next == null) {
                return false;
            }
            slow = slow.next;
            fast = fast.next.next;
        }
        return true;
    }

相关文章

网友评论

      本文标题:141. 环形链表

      本文链接:https://www.haomeiwen.com/subject/rbbeoctx.html