Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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: Optional[ListNode]) -> Optional[ListNode]:
- slow=head
- fast=head
- while fast and fast.next:
- slow=slow.next
- fast=fast.next.next #fast.next is already checked in the while condition
- return slow
Advertisement
Add Comment
Please, Sign In to add comment