# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
# def middleNode(self, head):
# """
# :type head: ListNode
# :rtype: ListNode
# """
# res = []
# while head:
# res.append(head)
# head = head.next
# return res[len(res) / 2]
def middleNode(self, head):
# Fast point is 2 times faster than slow point
fast = slow = head
while fast and fast.next:
slow = slow.next
fast = fast.next.next
return slow
Download Middle of the Linked List.pyLeetcode 876 Middle of the Linked List problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.
Feedback is the most important part of any website.
If you have any query, suggestion or feedback, Please feel free to contact us.