diff --git a/README.md b/README.md deleted file mode 100644 index 7c3b229..0000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Algorithms 2019-2020 Python LEETCODE - -Check branches for information. \ No newline at end of file diff --git a/linked-list.md b/linked-list.md new file mode 100644 index 0000000..8902728 --- /dev/null +++ b/linked-list.md @@ -0,0 +1,28 @@ +# Linked list + ++ [Remove Nth Node From End of List](#remove-nth-node-from-end-of-list) + +## Remove Nth Node From End of List + +https://leetcode.com/problems/remove-nth-node-from-end-of-list/ + +```python +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def removeNthFromEnd(self, head, n): + pastNode = nextNode = head + for i in range(n): + nextNode = nextNode.next + if not nextNode: + return head.next + while nextNode.next: + nextNode = nextNode.next + pastNode = pastNode.next + pastNode.next = pastNode.next.next + return head + +``` \ No newline at end of file