Skip to content

Commit 20b94bc

Browse files
committed
Update solution 876 [Python3]
1 parent 2813b65 commit 20b94bc

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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):
9+
"""
10+
:type head: ListNode
11+
:rtype: ListNode
12+
"""
13+
if not head:
14+
return None
15+
if not head.next:
16+
return head
17+
fast=head
18+
slow=head
19+
while fast.next:
20+
fast=fast.next.next
21+
slow=slow.next
22+
if not fast or not fast.next:
23+
return slow

0 commit comments

Comments
 (0)