Skip to content

Create remove-nth-node-from-end-list.py#1

Open
Eliguus wants to merge 1 commit intomainfrom
remove-nth-node-from-end-list
Open

Create remove-nth-node-from-end-list.py#1
Eliguus wants to merge 1 commit intomainfrom
remove-nth-node-from-end-list

Conversation

@Eliguus
Copy link
Owner

@Eliguus Eliguus commented Feb 21, 2023

this is my solution

@Eliguus Eliguus requested a review from Segnicho February 21, 2023 12:58
Copy link
Collaborator

@Segnicho Segnicho left a comment

Choose a reason for hiding this comment

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

``

def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]:
dummy = ListNode()
dummy.next = head
ptr_d = dummy
Copy link
Collaborator

Choose a reason for hiding this comment

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

you should use clearer variable names

while ptr_h:
ptr_d = ptr_d.next
ptr_h = ptr_h.next
ptr_d.next = ptr_d.next.next
Copy link
Collaborator

Choose a reason for hiding this comment

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

here you could check for a null pointer
if ptr_d.next: ptr_d.next = ptr_d.next.next

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