Skip to content

Added solution for problem 0142 linked list cycle 2 in python#5935

Open
Sanskar-Dwivedi wants to merge 1 commit into
neetcode-gh:mainfrom
Sanskar-Dwivedi:solution-for-0142-Linked-List-Cycle-II
Open

Added solution for problem 0142 linked list cycle 2 in python#5935
Sanskar-Dwivedi wants to merge 1 commit into
neetcode-gh:mainfrom
Sanskar-Dwivedi:solution-for-0142-Linked-List-Cycle-II

Conversation

@Sanskar-Dwivedi

@Sanskar-Dwivedi Sanskar-Dwivedi commented Jun 27, 2026

Copy link
Copy Markdown

Note

Add Python solution for LeetCode 0142 Linked List Cycle II

Adds 0142-linked-list-cycle-II.py with a Solution.detectCycle method using Floyd's cycle detection algorithm. The method uses slow/fast pointers to find a meeting point, then resets one pointer to head and advances both one step at a time to find the cycle entry node, returning None if no cycle exists.

Macroscope summarized be4e1c3.

Copilot AI review requested due to automatic review settings June 27, 2026 07:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a Python solution for LeetCode 0142 – Linked List Cycle II, implementing Floyd’s cycle detection to return the cycle entry node (or None).

Changes:

  • Introduces Solution.detectCycle using fast/slow pointers and entry-point detection.
  • Adds a new Python solution file for problem 0142.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,12 @@
class Solution(object):
Comment on lines +1 to +12
class Solution(object):
def detectCycle(self, head):
slow=fast=head
while fast and fast.next:
slow,fast=slow.next,fast.next.next
if slow==fast:
break
else:
return None
while head!=slow:
head,slow =head.next,slow.next
return head No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants