https://oj.leetcode.com/problems/linked-list-cycle/
这个题是一个求链表是否包含环的问题,主要是用一个哈希图来做的,确保现在收到的点是之前没有搜过的,如果之前搜过那说明有回路。。
public boolean hasCycle(ListNode head) {
if(head == null)return false;
ListNode head1,head2=null;
HashMap<ListNode, ListNode> hashmap = new HashMap<>();
hashmap.put(head, head);
head1 = head.next;
while(head1!=null){
head2 = hashmap.get(head1);
if(head2 == head1)return true;
hashmap.put(head1, head1);
head1 = head1.next;
}
return false;
}