-
Notifications
You must be signed in to change notification settings - Fork 0
/
876.py
46 lines (44 loc) · 1011 Bytes
/
876.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution1(object):
def middleNode(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
init_head=head
list=[]
while head!=None:
list.append(head.val)
head=head.next
middle=int(len(list)/2)
i=0
head=init_head
while i < middle:
i+=1
head=head.next
return head
class Solution2(object):
def middleNode(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
slow=head
fast=head
while fast and fast.next:
slow=slow.next
fast=fast.next.next
return slow
#%%
from node_creater import SLL
sll=SLL()
list=[1,2,3,4,'ssd']
for i in list:
sll.add_node(i)
#%%
x=Solution2
Solution2.middleNode(x,sll.head)