题目:
leetcode刷题 Day09
代码:

public class Solution {
    public boolean hasCycle(ListNode head) {
        //哈希值集合
        Set<ListNode> set=new HashSet<>();
        while(head!=null){
            if(set.contains(head)){
                return head;
            }else{
                set.add(head);
                head=head.next;
            }
        }
        return null;
        
    }
}

运行结果:
leetcode刷题 Day09

相关文章:

  • 2021-12-18
  • 2021-11-02
  • 2022-01-11
  • 2021-10-28
  • 2021-11-06
  • 2021-07-26
  • 2021-04-10
  • 2021-06-16
猜你喜欢
  • 2021-06-24
  • 2021-12-27
  • 2021-12-24
  • 2021-12-24
  • 2021-12-28
相关资源
相似解决方案