(LeetCode)Delete Node in a Linked List --- 删除链表中结点

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.

Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3,
the linked list should become 1 -> 2 -> 4after calling your function.

Subscribe to see which companies asked this question

解题分析:

基本的题意就是将指定的node delete,我使用python实现,这里不涉及到指针的问题,这里就是将node的l后一个结点 value 赋值给前一个value,

后一个node的next 赋值给这个node的next

# -*- coding:utf-8 -*-
__author__ = 'jiuzhang'
class ListNode(object):
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution(object):
    def deleteNode(self, node):
        node.val = node.next.val
        node.next - node.next.next
时间: 2024-08-14 03:55:05

(LeetCode)Delete Node in a Linked List --- 删除链表中结点的相关文章

[LeetCode] Delete Node in a Linked List 删除链表的节点

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 ->

[CareerCup] 2.3 Delete Node in a Linked List 删除链表的节点

2.3 Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.EXAMPLEInput: the node c from the linked list a->b->c->d->eResult: nothing is returned, but the new linked list looks like a- >

[LeetCode]79. Delete Node in a Linked List删除链表节点

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 ->

LeetCode237_Delete Node in a Linked List(删除链表中的节点) Java题解

题目: Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 -

leetcode_237题——Delete Node in a Linked List(链表)

Delete Node in a Linked List Total Accepted: 6113 Total Submissions: 12798My Submissions Question Solution Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2

lintcode 容易题:Remove Nth Node From End of Lis 删除链表中倒数第n个节点

题目: 删除链表中倒数第n个节点 给定一个链表,删除链表中倒数第n个节点,返回链表的头节点.  样例 给出链表1->2->3->4->5->null和 n = 2. 删除倒数第二个节点之后,这个链表将变成1->2->3->5->null. 注意 链表中的节点个数大于等于n 解题: 要删除倒数第n个节点,我们要找到其前面一个节点,也就是倒数第n+1的节点,找到这个节点就可以进行删除.和上题的思想很类似, 定义两个指针,p和cur,cur指针向前走,走了n

LeetCode——Delete Node in a Linked List

Description: Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1

[LeetCode] Delete Node in a Linked List

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 ->

LeetCode OJ:Delete Node in a Linked List(链表节点删除)

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 ->