How to remove Nth Node from the end of a linked list? | SoloLearn: Learn to code for FREE!

+11

How to remove Nth Node from the end of a linked list?

5/23/2020 2:24:18 PM

Isabella

4 Answers

New Answer

+4

If you mean a deque() object, a way to remove the Nth element would be to: .rotate(-N) .popleft() .rotate(N) So, for Nth from the end, it would go: .rotate(N) .pop() .rotate(-N) or simply use del: from collections import deque D = deque([1, 4, 3, 11, 8]) del D[-3] print(D) >>> deque([1, 4, 11, 8])

+8

Python

+5

Kuba Siekierzyński Thank you

+1

language?