题目描述
思路:遍历整个单链表,把所有节点放到HashSet中,如果有重复项,则说明有环。
public class Solution {
public boolean hasCycle(ListNode head) {
Set<ListNode> seen = new
题目描述
思路:遍历整个单链表,把所有节点放到HashSet中,如果有重复项,则说明有环。
public class Solution {
public boolean hasCycle(ListNode head) {
Set<ListNode> seen = new