• 2.10

    • 依旧秒
  • 1.24

    • 依旧秒了
  • 1.19

    • 秒了,set 集合搞定

需要返回指定点时,还是使用set方法吧

  • 11.9
    • 返回的是ListNode,new忘了加,秒了
public class Solution {
    public ListNode detectCycle(ListNode head) {
        Set<ListNode> set = new HashSet<>();
        ListNode l = head;
        while(l!=null){
            boolean r= set.contains(l);
            if(r){
                return l;
            }
            set.add(l);
            l=l.next;
        }
        return null;
    }
}
  • 是Set不是Map

  • set.add()而不是set.put()

  • set.contains而不是set.contain