We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cb4a265 commit c3af296Copy full SHA for c3af296
Python/chapter02/2.1 - Remove Dups/miguel_2.1_sol.py
@@ -19,18 +19,19 @@ def __init__(self, d: int):
19
class LinkedList:
20
def __init__(self, initial_value: int = None):
21
self.head = None
22
+ self.tail = None
23
if initial_value is not None:
24
self.head = Node(initial_value)
25
+ self.tail = self.head
26
27
def append_to_tail(self, d: int) -> None:
28
if self.head is None:
29
self.head = Node(d)
30
31
return
32
end = Node(d)
- n = self.head
- while n.next is not None:
- n = n.next
33
- n.next = end
+ self.tail.next = end
34
+ self.tail = end
35
36
def append_to_head(self, d: int) -> None:
37
new_head = Node(d)
0 commit comments