public static ListNode detectCycle(ListNode head) {
        if(head == null || head.next == null) return null;

        ListNode slow = head.next;
        ListNode fast = head.next.next;

        while(fast != null && fast.next != null){
            if(slow == fast){
                ListNode node = head;
                while(node != slow){
                    node = node.next;
                    slow = slow.next;
                }
                return node;
            }else{
                slow = slow.next;
                fast = fast.next.next;
            }
        }
        return null;
    }