Problem
Given a linked list, remove the n-th node from the end of list and return its head.
Example
1 | Given linked list: 1->2->3->4->5, and n = 2. |
Solution
Method: Iterative
Time Complexity:
Space Complexity:
1 | # Definition for singly-linked list. |
Solution2
Method: Iterative
Time Complexity: O(n)
Space Complexity:
1 | # Definition for singly-linked list. |
Solution3[1]
Method:
Time Complexity:
Space Complexity:
1 | # value shifting |
Solution4[1]
Method:
Time Complexity:
Space Complexity:
1 | # index and remove |
Solution5[1]
Method:
Time Complexity:
Space Complexity:
1 | # n ahead |
Reference
[1] https://leetcode.com/problems/remove-nth-node-from-end-of-list/discuss/8802/3-short-Python-solutions