Skip to content

all tests passed #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

all tests passed #98

wants to merge 1 commit into from

Conversation

PoppyMeng
Copy link

No description provided.

Copy link

@kyra-patton kyra-patton left a comment

Choose a reason for hiding this comment

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

Nice attempt! Looks like there were some slight misunderstandings about the logic. I added some tips on how you might refactor to pass all the tests.

Please reach out if you have questions.

return None
p1, p2 = headA, headB
while p1.val!= p2.val:

Choose a reason for hiding this comment

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

We want to compare the node objects and not just their values. Two nodes can have the same values but be different objects in memory!

Suggested change
while p1.val!= p2.val:
while p1 != p2:

Comment on lines +18 to +19
p2 = p2.next if p2.next else headA

Choose a reason for hiding this comment

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

Your current code causes an infinite loop in some cases.
If you make this change, what will happen is p1 will become each node in list A, then each node in list B and then get set to None.
p2 will become each node in list B and then each node in list B and get set to None at the same time as p1 gets set to None. Then the while loop condition will become Falsey, and you'll return None.

When you set p1 to p1.next only if p1.next exists (and the equivalent with p2) they never get set to None therefore you end up in an infinite loop.

Try using the debugger on test case 4 test_will_return_none_when_no_intersection to see what happens.

Suggested change
p1 = p1.next if p1.next else headB
p2 = p2.next if p2.next else headA
p1 = p1.next if p1 else headB
p2 = p2.next if p2 else headA
Suggested change
p1 = p1.next if p1.next else headB
p2 = p2.next if p2.next else headA
p1 = p1.next if p1.next else headB
p2 = p2.next if p2.next else headA

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