#237.    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 -> 4 after calling your function.

题解:将下个结点的值赋值给当前结点,将下一结点删除即可。

/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
void deleteNode(ListNode* node) {
node->val=node->next->val;
node->next=node->next->next;
}
};

Leetcode-237 Delete Node in a Linked List的更多相关文章

  1. [LeetCode] 237. 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 th ...

  2. LeetCode 237. 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 th ...

  3. [LeetCode] 237. 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 th ...

  4. (easy)LeetCode 237.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 th ...

  5. leetcode 237 Delete Node in a Linked List python

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

  6. 17.leetcode 237. 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 th ...

  7. [Leetcode]237. Delete Node in a Linked List -David_Lin

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

  8. LeetCode 237. Delete Node in a Linked List 删除链表结点(只给定要删除的结点) C++/Java

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

  9. [LeetCode] 237. Delete Node in a Linked List_Easy tag: Linked List

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

  10. LeetCode 237 Delete Node in a Linked List 解题报告

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

随机推荐

  1. java多线程学习-同步(synchronized)

    (示例都是网上视频的) 假如两个线程同时调用一个方法输出字符串 public class SynchronizedTest extends Thread { public static void ma ...

  2. lvm snapshot(lvm 快照)

    lvm快照有多种实现方法,其中一种是COW(Copy-On-Write),不用停止服务或将逻辑卷设为只读就可以进行备份,当一个 snapshot创建的时候只是拷贝原始卷里的元数据,而不是物理上的数据, ...

  3. windows all version - 实现指定路径共享

    调用API函数NetShareAdd()将文件夹设置为共享,调用此函数后如果不做其他设置,网络用户是无法访问共享文件夹的,因为此文件夹在NTFS分区中,同时受到NTFS文件系统的访问控制,因此还需要第 ...

  4. android 区分wifi是5G还是2.4G

    http://bbs.csdn.net/topics/391033966?page=1 我一开始看这帖子,找不到答案,为了后来的人,我来回复吧.WifiManager wifiManager = (W ...

  5. DBHelper

    DBHelper: using System; using System.Collections.Generic; using System.Linq; using System.Text; usin ...

  6. JavaScript-插入concat,splice,截取slice

    拼接和截取:concat 拼接: var newArr=arr.concat(值1,值2,值3,值4,.....); 将值1值2,以及arr2中每个元素一次拼接到arr1结尾,返回新数组 强调: 1. ...

  7. Android webview 上传文件不调用openFileChooser解决办法

    html页面带有图片上传功能,关于使用openFileChooser方法去选择图片,并且在onActivityResult方法里面设置返回的图片url文件路径,网上有很多,再次不再赘述. 实践中发现, ...

  8. 人脸识别经典算法二:LBP方法

    与第一篇博文特征脸方法不同,LBP(Local Binary Patterns,局部二值模式)是提取局部特征作为判别依据的.LBP方法显著的优点是对光照不敏感,但是依然没有解决姿态和表情的问题.不过相 ...

  9. iOS ViewController生命周期

    ViewController是view的controller,viewController的职责主要包括管理内部各个view的加载显示与卸载,同时负责与其他ViewController的通信和协调. ...

  10. [Phalcon-framework] Phalcon framework - Dependency Injection/Service Location And the MVC architecture note 1

    Registering services in the Container - We can easily replace a component with one created by oursel ...