跳至主要內容
141. 环形链表

141. 环形链表

解法一:Set 存储

public class Solution {
    public boolean hasCycle(ListNode head) {
        HashSet<ListNode> set = new HashSet<>();
        while (head != null){
            if(!set.add(head)) return true; // add() 未添加成功返回 false
            head = head.next;
        }
        return false;
    }
}

T4mako...小于 1 分钟算法哈希表链表双指针
2
3