From 092ed5f44cf29b6fceb5440995108d3bec90c51b Mon Sep 17 00:00:00 2001 From: Yukti Khosla <44090430+Yukti-09@users.noreply.github.com> Date: Mon, 31 Aug 2020 08:10:44 +0530 Subject: [PATCH] Create Middle_of_Linked_List.py --- .../linked_list/Middle_of_Linked_List.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 data_structures/linked_list/Middle_of_Linked_List.py diff --git a/data_structures/linked_list/Middle_of_Linked_List.py b/data_structures/linked_list/Middle_of_Linked_List.py new file mode 100644 index 00000000..dc33d4f9 --- /dev/null +++ b/data_structures/linked_list/Middle_of_Linked_List.py @@ -0,0 +1,18 @@ +# Definition for singly-linked list. + class ListNode: + def __init__(self, val=0, next=None): + self.val = val + self.next = next +class Solution: + def middleNode(self, head: ListNode) -> ListNode: + temp = head + count = 0 + while(temp!=None): + count+=1 + temp=temp.next + count=int(count/2) + i=0 + while(i!=count): + head=head.next + i+=1 + return(head)