标签:range oid i+1 etc 节点 modify on() ext auth
237class Solution:
def deleteNode(self, node):
"""
:type node: ListNode
:rtype: void Do not return anything, modify node in-place instead.
"""
node.val=node.next.val
node.next=node.next.next
head1 = ListNode(4)
n1 = ListNode(5)
n2 = ListNode(1)
n3 = ListNode(9)
head1.next = n1
n1.next = n2
n2.next = n3
t=Solution()
t.deleteNode(n1)
print(head1.next.val)
876
"""
Created on Thu Nov 22 21:45:28 2018
@author: Administrator
"""
class ListNode:
def init(self, x):
self.val = x
self.next = None
class Solution(object):
def middleNode(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
flag=True
i=0
t=head
while flag:
if t.next!=None:
i=i+1
t=t.next
else:
flag=False
i=i+1
j=int(i/2)+1
for m in range(0,j-1):
head=head.next
return head
head1 = ListNode(1)
n1 = ListNode(2)
n2 = ListNode(3)
n3 = ListNode(4)
n4 = ListNode(5)
head1.next = n1
n1.next = n2
n2.next = n3
n3.next = n4
t=Solution()
print(t.middleNode(head1).val)
#print(head1.next.val)
每日一题之LeetCode237删除链表中的节点876链表的中间节点
标签:range oid i+1 etc 节点 modify on() ext auth
原文地址:http://blog.51cto.com/13930723/2320836