コード例 #1
0
        private static ListNode <int> FindLoopNode(Structures.LinkedList <int> linkedList)
        {
            var slow = linkedList.Head();
            var fast = linkedList.Head();

            while (fast != null && fast.Next != null)
            {
                slow = slow.Next;
                fast = fast.Next.Next;

                if (slow == fast)
                {
                    return(slow);
                }
            }

            return(null);

            // var dic = new Dictionary<ListNode<int>, int>();

            // return FindLoopNode(linkedList.Head(), dic);
        }