Skip to content

Instantly share code, notes, and snippets.

@atul-chaudhary
Created September 29, 2019 03:55
Show Gist options
  • Save atul-chaudhary/db44f653b2ced6c10224d1bdbac81bcf to your computer and use it in GitHub Desktop.
Save atul-chaudhary/db44f653b2ced6c10224d1bdbac81bcf to your computer and use it in GitHub Desktop.
leetocde 876: Find the middle element of linked list
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def middleNode(self, head: ListNode) -> ListNode:
fst=head
slw=head
while(fst is not None and fst.next is not None):
fst=fst.next.next
slw=slw.next
return slw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment