From 5d7c2f0427aa3528ef608fa1a862163912d9c093 Mon Sep 17 00:00:00 2001 From: Akash Shaw Date: Fri, 1 Oct 2021 17:08:02 +0530 Subject: [PATCH] Create LengthofLinkedList.py --- Python/LengthofLinkedList.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Python/LengthofLinkedList.py diff --git a/Python/LengthofLinkedList.py b/Python/LengthofLinkedList.py new file mode 100644 index 00000000..5e35fca5 --- /dev/null +++ b/Python/LengthofLinkedList.py @@ -0,0 +1,29 @@ +class Node : + def __init__(self, data) : + self.data = data + self.next = None + + + + + + +def length(head): + curr = head + cnt = 0 + while curr is not None: + cnt += 1 + curr = curr.next + + return cnt + +def ll(arr): + print(arr) + if len(arr)==0: + return None + head = Node(arr[0]) + last = head + for data in arr[1:]: + last.next = Node(data) + last = last.next + return head