import java.util.*;
/**
 * Definition for singly-linked list.
 * class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) {
 *         val = x;
 *         next = null;
 *     }
 * }
 */
public class Solution {
    public boolean hasCycle(ListNode head) {
        if(head ==null)
        {
            return false;
        }
        if(head.next == null){
            return false;
        }
        List<ListNode> arr = new ArrayList<>();
        int t = 0;
        while(head!=null){
            arr.add(head);
            head = head.next;
            if(find(arr,head))
            {
                t = 1;
                break;
            }
        }
        if(t == 1)
            return true;
        else
            return false;
    }
    public boolean find(List<ListNode> arr,ListNode target){
        
            if(arr.contains(target)){
                return true;
            }else{
                return false;
            }
        }
}