-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathExercise_3.py
More file actions
32 lines (28 loc) · 755 Bytes
/
Exercise_3.py
File metadata and controls
32 lines (28 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class ListNode:
"""
A node in a singly-linked list.
"""
def __init__(self, data=None, next=None):
class SinglyLinkedList:
def __init__(self):
"""
Create a new singly-linked list.
Takes O(1) time.
"""
self.head = None
def append(self, data):
"""
Insert a new element at the end of the list.
Takes O(n) time.
"""
def find(self, key):
"""
Search for the first element with `data` matching
`key`. Return the element or `None` if not found.
Takes O(n) time.
"""
def remove(self, key):
"""
Remove the first occurrence of `key` in the list.
Takes O(n) time.
"""