Quick actions

cmd+k|ctrl+k

Navigation

Languages

linkedList Middle

Snippet info

Language

Python

Visibility

public

Author

soham57

Created

2022-09-04T07:23:09.075997Z

Updated

2022-09-04T07:23:09.075997Z

def linkedListMiddle(self, head: Optional[ListNode]) -> int:
    #Initializing two linkedlist nodes slow & fast
    slow = head
    fast = head
    #Increment fast_ptr by 2 and slow_ptr by 1 positions until fast_ptr and fast_ptr.next is not NULL
    while(fast and fast.next):
        slow = slow.next
        fast = fast.next.next
    #Return the value at slow_ptr.
    return slow.data
INFO