0
点赞
收藏
分享

微信扫一扫

141. 环形链表(简单)

律楷粑粑 2022-01-13 阅读 73

在这里插入图片描述

public class Solution {
    //n 1
    public boolean hasCycle(ListNode head) {
        ListNode slow = head, fast = head;
        while (fast!= null && fast.next!= null) {
            slow = slow.next;
            fast = fast.next.next;
            if (slow == fast) {
                return true;
            }
        }
        return false;
    }
}
举报

相关推荐

0 条评论