Conversation
| # Time Complexity: ? | ||
| # Space Complexity: ? |
There was a problem hiding this comment.
What do you think the space and time complexity of this is? Is the time complexity dependent on the length of the linked list? Is there any new variables being created that grow larger depending upon the input?
| # Time Complexity: ? | ||
| # Space Complexity: ? |
There was a problem hiding this comment.
What do you think the space and time complexity of this is? Is the time complexity dependent on the length of the linked list? Is there any new variables being created that grow larger depending upon the input?
| # Time Complexity: ? | ||
| # Space Complexity: ? |
There was a problem hiding this comment.
What do you think the space and time complexity of this is? Is the time complexity dependent on the length of the linked list? Is there any new variables being created that grow larger depending upon the input?
| # Time Complexity: ? | ||
| # Space Complexity: ? |
There was a problem hiding this comment.
What do you think the space and time complexity of this is? Is the time complexity dependent on the length of the linked list? Is there any new variables being created that grow larger depending upon the input?
| # Time Complexity: ? | ||
| # Space Complexity: ? |
There was a problem hiding this comment.
What do you think the space and time complexity of this is? Is the time complexity dependent on the length of the linked list? Is there any new variables being created that grow larger depending upon the input?
| while current.next != None: | ||
| current = current.next | ||
| current.next = new_node | ||
| self.tail = current.next |
There was a problem hiding this comment.
do we need this while loop? we already have a pointer to the last node because of self.tail, so we can just do this:
| while current.next != None: | |
| current = current.next | |
| current.next = new_node | |
| self.tail = current.next | |
| self.tail.next = new_node |
| # method that inserts a given value as a new last node in the linked list | ||
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| def add_last(self, value): |
|
|
||
| # method to return the max value in the linked list | ||
| # returns the data value and not the node | ||
| def find_max(self): |
| if current.value == value: | ||
| current.next = current.next.next | ||
| return | ||
| prev = current | ||
| current = current.next | ||
| if current.value == value: | ||
| prev.next = None | ||
| self.tail = prev |
There was a problem hiding this comment.
We want to stop a node earlier in order to drop the deleted node in one line:
| if current.value == value: | |
| current.next = current.next.next | |
| return | |
| prev = current | |
| current = current.next | |
| if current.value == value: | |
| prev.next = None | |
| self.tail = prev | |
| if current.next.value == value: | |
| current.next = current.next.next | |
| current = current.next |
| @@ -89,7 +152,15 @@ def visit(self): | |||
| # Time Complexity: ? | |||
| # Space Complexity: ? | |||
| def reverse(self): | |||
No description provided.