[LeetCode][python3]0019. Remove Nth Node From End of List

class Solution:
def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
con=0
p=head
while p!=None:
p=p.next
con+=1
con-=n
#print(head,con)
p=head
#print(p)
if con==0:
head=head.next
return head

for i in range(con-1):
p=p.next
p.next=p.next.next
return head
N2I -2020.04.02

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ruka

Ruka

HI I’m Ruka. Now a SWE in Taiwan. Contact via email: nayzi9999@gmail.com