9. 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.
Subscribe to see which companies asked this question
难度:easy
思路:将后面节点的值交换到前面
/**
* 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) {
if(node!=NULL)
{
node->val = node->next->val;
node->next = node->next->next;
}
}
};
9. Delete Node in a Linked List的更多相关文章
- 【4_237】Delete Node in a Linked List
Delete Node in a Linked List Total Accepted: 48121 Total Submissions: 109297 Difficulty: Easy Write ...
- Leetcode-237 Delete Node in a Linked List
#237. Delete Node in a Linked List Write a function to delete a node (except the tail) in a singl ...
- [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 ...
- 【LeetCode】237 & 203 - Delete Node in a Linked List & Remove Linked List Elements
237 - Delete Node in a Linked List Write a function to delete a node (except the tail) in a singly l ...
- 237. Delete Node in a Linked List(C++)
237. Delete Node in a Linked Lis t Write a function to delete a node (except the tail) in a singly l ...
- [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 ...
- LeetCode Javascript实现 283. Move Zeroes 349. Intersection of Two Arrays 237. Delete Node in a Linked List
283. Move Zeroes var moveZeroes = function(nums) { var num1=0,num2=1; while(num1!=num2){ nums.forEac ...
- 237. Delete Node in a Linked List【easy】
237. Delete Node in a Linked List[easy] Write a function to delete a node (except the tail) in a sin ...
- LeetCode_237. Delete Node in a Linked List
237. Delete Node in a Linked List Easy Write a function to delete a node (except the tail) in a sing ...
- [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 th ...
随机推荐
- 计算机网络之网络层IP组播(IGMP、组播路由选择协议、组播地址)
文章转自:https://blog.csdn.net/weixin_43914604/article/details/105318560 学习课程:<2019王道考研计算机网络> 学习目的 ...
- 2021NOI同步赛
\(NOI\) 网上同步赛 明白了身为菜鸡的自己和普通人的差距 DAY1 \(T1\) 轻重边 [题目描述] 小 W 有一棵 \(n\) 个结点的树,树上的每一条边可能是轻边或者重边.接下来你需要对树 ...
- JAVA笔记7__接口应用/Object类/简单工厂模式/静态代理模式/适配器模式
/** * 接口应用 */ public class Main { public static void main(String[] args) { Person p = new Person(&qu ...
- JAVA笔记5__构造块、静态块/单例设计模式/继承/final关键字/super关键字
public class Main { { //构造块(在构造对象时调用,先于构造方法执行) System.out.println("我是构造块!"); } static{ //静 ...
- Redis源码分析(skiplist)
源码版本: redis-4.0.1 源码位置: server.h :zskiplistNode和zskiplist的数据结构定义. t_zset.c: 以zsl开头的函数是SkipList相关的操作函 ...
- msfsploit框架的使用——ms17_010漏洞的利用
开门见山,首先输入msfconsole打开msf控制台 全球最牛逼的渗透测试框架就是长这个样子(每次打开时,显示的图案都不一样) 然后搜索ms17_010的相关模块,得到了六条结果,我们需要用的是编号 ...
- yrm的安装和使用
yrm的安装和使用 我们经常下载包的速度很忙有的还会卡住几十分钟,所以我们需要切换镜像,这样我们下载的速度会快很多 而yrm 是一个 yarn源管理器,允许你快速地在源间切换 安装 npm insta ...
- pipeline学习
目录 一.常用语法 二.基础使用 三.使用 Groovy 沙盒 四.参数化构建过程 五.pipeline script from SCM 六.参考 一.常用语法 1.拉取git仓库代码 checkou ...
- JDK 工具 HSDB 查看动态生成类
前置工作 1. 复制 JDK 安装目录\jre\bin\sawindbg.dll 到 JDK 安装目录同级的 jre\bin 目录下,否则会报错找不到 sawindbg.dll 文件. 比如我的 sa ...
- 菜鸡的Java笔记 数据表与简单java类映射
利用实际的数据表实现表与类的操作转换 简单java类是整个项目开发中的灵魂所在,它有自己严格的开发标准,而最为重要的是它需要于数据表是完全对应的 不过考虑到现在没有接触到过 ...