Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. # Definition for singly-linked list.
  2. # class ListNode:
  3. #     def __init__(self, x):
  4. #         self.val = x
  5. #         self.next = None
  6.  
  7. class Solution:
  8.     def middleNode(self, head: ListNode) -> ListNode:
  9.         #move right and
  10.         if head.next == None:
  11.             return head
  12.         elif head.next.next == None:
  13.             return head.next
  14.         curr = head
  15.         mid = curr
  16.         i = 0
  17.         mi = 0
  18.         while head.next != None:
  19.             if mi <= i/2:
  20.                 curr = curr.next
  21.                 mi+=1
  22.             head = head.next
  23.             i += 1
  24.         return curr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement