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)