代码:
'''剑指offer25:删除一个链表节点'''
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def deleteNode(self, head, val):
if head==None:
return None
if head.val == val:
return head.next
curr=head
while curr.next!=None and curr.next.val!=val:
curr=curr.next
curr.next=curr.next.next
return head