[刷题] 237 Delete Nodes in a Linked List
要求
- 给定链表中的一个节点,删除该节点
思路
- 通过改变节点的值实现

实现
1 struct ListNode {
2 int val;
3 ListNode *next;
4 ListNode(int x) : val(x), next(NULL) {}
5 };
6
7 class Solution {
8 public:
9 void deleteNode(ListNode* node) {
10
11 if( node == NULL )
12 return;
13
14 if( node->next == NULL){
15 delete node;
16 node = NULL;
17 return;
18 }
19
20 node->val = node->next->val;
21 ListNode* delNode = node->next;
22 node->next = delNode->next;
23
24 delete delNode;
25
26 return;
27 }
28 };
[刷题] 237 Delete Nodes in a Linked List的更多相关文章
- 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(C++)
237. Delete Node in a Linked Lis t Write a function to delete a node (except the tail) in a singly l ...
- 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 解题报告 (Java&Python&C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 设置当前节点的值为下一个 日期 [LeetCode] ...
- [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】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 t ...
- 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 ...
- [LeetCode&Python] Problem 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] 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 ...
随机推荐
- windows平台rust安装
1.安装目录环境变量 RUSTUP_HOME D:\WorkSoftware\Rust\cargo CARGO_HOME D:\WorkSoftware\Rust\rustup 2.安装下载加速环境变 ...
- 第30 章 : 理解 RuntimeClass 与使用多容器运行时
理解 RuntimeClass 与使用多容器运行时 本文将主要分享以下三方面的内容: RuntimeClass 需求来源 RuntimeClass 功能介绍 多容器运行时示例 RuntimeClass ...
- 微信小程序getUserProfile适配方案
清明节放假前一天 群里突然炸锅,说小程序所有用的昵称全部变成了微信昵称 当时我就 特么不是说好13号吗??? 吓得我赶紧爬起来翻文档(需要代码直接往后翻) wx.getUserProfile(Obje ...
- 深入理解Java并发框架AQS系列(四):共享锁(Shared Lock)
深入理解Java并发框架AQS系列(一):线程 深入理解Java并发框架AQS系列(二):AQS框架简介及锁概念 深入理解Java并发框架AQS系列(三):独占锁(Exclusive Lock) 深入 ...
- 茫茫内存,我该如何用 windbg 找到你 ?
一:背景 1. 讲故事 前天wx上有个朋友丢给我一个dump,让我帮忙鉴定一下某些敏感信息在内存中是否也是加密的,现在数据安全很重要,不仅数据库中的信息要加密,灌到内存后数据同样也需密文存储,随用随解 ...
- OO第四单元总结暨OO课程总结
一.第四单元作业总结 本单元的主要任务是对 Uml 图元素进行管理和查询,测试一开始会输入一个静态图,之后会对图中相关内容进行查询. 第13,14次作业 第14次作业新增内容很少,故与第13次作业放在 ...
- Spring Boot 整合Junit和redis
14. Spring Boot整合-Junit 目标:在Spring Boot项目中使用Junit进行单元测试UserService的方法 分析: 添加启动器依赖spring-boot-starter ...
- Java高级【Junit、反射、注解】
1.Junit单元测试 * 测试分类: 1. 黑盒测试:不需要写代码,给输入值,看程序是否能够输出期望的值. 2. 白盒测试:需要写代码的.关注程序具体的执行流程. * Junit使用 ...
- 安全开发Java:日志注入,并没那么简单
摘要:当web工程比较大,历史代码较多时, 应当使用log4j2框架的能力来修改日志注入问题,而不是按照有些博文里写的逐个进化参数的方式. 案例故事 某个新系统上线了,小A在其中开发了个简单的登录模块 ...
- 自动化kolla-ansible部署centos7.9+openstack-train-超融合单机架构
自动化kolla-ansible部署centos7.9+openstack-train-超融合单机架构 欢迎加QQ群:1026880196 进行交流学习 环境说明: 1. 满足一台电脑一个网卡的环 ...