You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"helpers_run_body": " head = ListNode.from_list(head_vals)\n # Keep reference to tail to break cycle later\n tail = None\n if head is not None:\n tail = head\n while tail.next is not None:\n tail = tail.next\n # Create cycle if pos is valid\n if pos >= 0 and head is not None and tail is not None:\n # Find the node at position pos\n cycle_node = head\n for _ in range(pos):\n cycle_node = cycle_node.next\n # Create cycle\n tail.next = cycle_node\n implementation = solution_class()\n result = implementation.detect_cycle(head)\n # Break the cycle to avoid infinite loop when finding index\n if tail is not None:\n tail.next = None\n # Return the index of the cycle node, or -1 if no cycle\n if result is None:\n return -1\n # Find index of result node\n index = 0\n current = head\n while current is not None and current != result:\n current = current.next\n index += 1\n return index if current is not None else -1",
31
+
"helpers_run_body": " head = ListNode.from_list(head_vals)\n # Keep reference to tail to break cycle later\n tail = None\n if head is not None:\n tail = head\n while tail.next is not None:\n tail = tail.next\n # Create cycle if pos is valid\n if pos >= 0 and head is not None and tail is not None:\n # Find the node at position pos\n cycle_node = head\n for _ in range(pos):\n assert cycle_node is not None\n cycle_node = cycle_node.next\n # Create cycle\n tail.next = cycle_node\n implementation = solution_class()\n result = implementation.detect_cycle(head)\n # Break the cycle to avoid infinite loop when finding index\n if tail is not None:\n tail.next = None\n # Return the index of the cycle node, or -1 if no cycle\n if result is None:\n return -1\n # Find index of result node\n index = 0\n current = head\n while current is not None and current != result:\n current = current.next\n index += 1\n return index if current is not None else -1",
0 commit comments