c17, seaturtle, csfun a - Shelby Faulconer#4
Open
pickled-bot wants to merge 5 commits intoAdaGold:mainfrom
Open
c17, seaturtle, csfun a - Shelby Faulconer#4pickled-bot wants to merge 5 commits intoAdaGold:mainfrom
pickled-bot wants to merge 5 commits intoAdaGold:mainfrom
Conversation
…ntersection.py adjusted for the same reason (removed .value)
…rks properly with links of different length
char-adadev
reviewed
Sep 28, 2022
| current_a = headA | ||
| current_b = headB | ||
|
|
||
| while headA and headB: |
Contributor
There was a problem hiding this comment.
This is super close to getting all the tests to pass, great job!!
For getting that last test to pass, I would take a look at a couple of things:
- Try running without the outer loop
while headA and headB. Is there any difference? You might not need this loop since you're not advancing the pointers for headA and headB. - Due to your if, elif, else statement at the bottom of the
while headA and headBloop, the loop may just be running one time before returning - I would recommend walking through your solution with two small example lists like:
1 -> 2 -> 3
2 -> 3
Do you run into any null pointers while walking through your code?
You may notice that your solution is erroring out on line 32 or line 33 for differing length lists. It seems as if the pointers are advancing one-by-one without making a double check to see if one list has reached the end and resetting the pointer (which you do have a check for in lines 25 through 33!).
I was able to re-work your solution very slightly to get all the tests to pass from my side:
first = None
current_a = headA
current_b = headB
while current_a != current_b:
if current_a is None and current_b is not None:
current_a = headA
current_b = current_b.next
elif current_b is None and current_a is not None:
current_b = headB
current_a = current_a.next
else:
current_a = current_a.next
current_b = current_b.next
if current_a == current_b:
first = current_a
return first
elif current_a != current_b:
return first
else:
return first
Overall, you did a great job and I can tell you put a lot of effort into this!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Creating pull request even though test for linkedLists of different size is not passing wanted to open the pull request before getting this test to pass.
Added a test to check if the last node is the same, and to return that node.