Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Definition for singly-linked list.
- # class ListNode:
- # def __init__(self, x):
- # self.val = x
- # self.next = None
- class Solution:
- def middleNode(self, head: ListNode) -> ListNode:
- #move right and
- if head.next == None:
- return head
- elif head.next.next == None:
- return head.next
- curr = head
- mid = curr
- i = 0
- mi = 0
- while head.next != None:
- if mi <= i/2:
- curr = curr.next
- mi+=1
- head = head.next
- i += 1
- return curr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement