Closed
Description
While getting the length of the linked list, code will take O(n) of unnecessary time as it executes -
len(tuple(iter(self)))
This also takes up O(n) of extra space as it is creating a tuple first.
This can be easily avoided by maintaining an instance variable len
, increment/decrement it while inserting/deleting elements.
Metadata
Metadata
Assignees
Labels
No labels