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

  1. My first solution
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

--

--

--

HI I’m N2I. Now a SWE in Taiwan. Check out more about me in https://nzi2020.blogspot.com/ or contact via email: nayzi9999@gmail.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

New Mainnet Version of the Endor Protocol

How to update AWS ECS service

Jobify: Sinatra CMS App

IBM Cloud Pak for Data’s Future for Storage Support

CRODO BEST IDO PLATFORM?

An Alternative Strategy to API Polling Using Pub/Sub and MQTT

No-Code Space Set to Grow 3 Times in the Next 3 Years

Live in Beta! 🏁 Celebrating with $15k Hackathon 🎉

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
N2I

N2I

HI I’m N2I. Now a SWE in Taiwan. Check out more about me in https://nzi2020.blogspot.com/ or contact via email: nayzi9999@gmail.com

More from Medium

LeetCode Patterns Adventure 27 — Lowest Common Ancestor of a Binary Search Tree

Heaps, the python way

heap

Pattern 4: Merge Intervals

Course Schedule: Leetcode — Blind 75 (Graph)