LeetCode 203. Remove Linked List Elements Solution Explained - Python

preview_player
Показать описание


Python Code:

-------------------------------------------------------------

class Solution:
def removeElements(self, head, val):

dummy = ListNode(None)

prev = dummy
curr = head

while curr:


else:
prev = curr


--------------------------------------------------------------------

Time complexity: O(N), it has to iterate through the length of the dataset N.

Space complexity: O(1), regardless of the dataset size, the space complexity is constant.
Рекомендации по теме
Комментарии
Автор

this is awesome :) I really appreciate the different colored pens!

elysel
Автор

Thank you so much such a wonderful explanation

gurunathreddy
Автор

I thought i could solve this on my own within 10 minutes 2 hours in and now i feel like i chose the wrong career 😭😭

NoRa-wsfo