Challenge 1: Length of a Linked List
Find the length of the given linked list.
We'll cover the following
Problem Statement
Implement a function that takes a linked list testVariable
and returns the length of the linked list.
Input
- A variable
testVariable
containing the linked list whose length needs to be calculated. - The head node of the linked list
head
.
Output
Length of the input linked list
Sample Input
testVariable => 3 -> 4 -> 7 -> 11 -> None
head => 3
Sample Output
4
Try it Yourself
Try to attempt this challenge by yourself before moving on to the solution. Good luck!
main.py
linkedList.py
node.py
import linkedList as ldef length(testVariable, head) :# Write your code herereturn None
In the next lesson, we have a solution review of this problem.