Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # your task is to complete this function
- '''
- class node:
- def __init__(data):
- self.data = data
- self.next = None
- '''
- class Solution:
- # Should return data of middle node. If linked list is empty, then -1
- def findMid(self, head):
- if head is None:
- return -1
- slow = head
- fast = head
- while fast is not None and fast.next is not None:
- slow = slow.next
- fast = fast.next.next
- return slow.data
- # return the value stored in the middle node
Advertisement
Add Comment
Please, Sign In to add comment