mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-12 12:28:04 +00:00
Added method to return the length of a linked list.
This commit is contained in:
@@ -10,6 +10,14 @@ class Node(object):
|
||||
class LinkedList(object):
|
||||
def __init__(self, head=None):
|
||||
self.head = head
|
||||
|
||||
def __len__(self):
|
||||
curr = self.head
|
||||
counter = 0
|
||||
while curr is not None:
|
||||
counter += 1
|
||||
curr = curr.next
|
||||
return counter
|
||||
|
||||
def insert_to_front(self, data):
|
||||
if data is None:
|
||||
|
||||
Reference in New Issue
Block a user