码迷,mamicode.com
首页 > 其他好文 > 详细

每日一题之LeetCode237删除链表中的节点876链表的中间节点

时间:2018-11-22 23:06:17      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:range   oid   i+1   etc   节点   modify   on()   ext   auth   

237
class ListNode:
def init(self, x):
self.val = x
self.next = None

class 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

-- coding: utf-8 --

"""
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

while k:

head=head.next

n=n+1

if n=j:

k=False

    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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!