[刷题] 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 ...
随机推荐
- 敏捷史话(十二):你现在接触的敏捷也许是“黑暗敏捷”——Ron Jeffries
他很少提起往事,也不再提及二十年前那场引起软件行业变革的会议,他专注于当下,一直活跃在敏捷领域.八十多岁的他依然运营维护着网站和博客,是极限编程网站 XProgramming.com 的作者,该网站是 ...
- 单链表c语言实现的形式
包括初始化,创建,查询,长度,删除,清空,销毁等操作 代码如下: #include<stdio.h> #include<stdlib.h> //定义单链表的数据类型 typed ...
- 灵雀云Istio技术实践专题整理
Istio技术实践专题(1) Service Mesh Istio 基本概念和架构基础 Istio被称作Kubernetes的最佳云原生拍档.从今天起,我们推出"Istio技术实践" ...
- C#中protobuf-net的编码结构及使用方法
目录 protobuf-net简介 ProtoBuf编码原理 编码结构 解析一个编码结果 使用方法 参考资料 protobuf-net简介 Protocol Buffer(简称Protobuf) 是 ...
- MySQL常用配置参数说明
1.sync_binlog sync_binlog=0,当事务提交之后,MySQL不做fsync之类的磁盘同步指令刷新binlog_cache中的信息到磁盘,而让Filesystem自行决定什么时候来 ...
- PMP考位抢夺攻略(二)
为什么会有第二篇文章呢,因为北京周边的考点太难抢了,都不是页面样式能不能展示的问题了!!! 如何在网页完全打不开的情况下报考PMP? 首先,自动登录. 打开浏览器,输入网址http://exam.ch ...
- Python 高级特性(4)- 生成器
列表生成式 通过上一篇介绍 列表生成式文章可以知道,它可以快速创建我们需要的列表 局限性 受内存限制,列表生成式创建的列表的容量肯定有限的 不仅占用很大的存储空间,如果我们仅仅需要访问前几个元素,那后 ...
- Day02_13_Javadoc_生成帮助文档
JavaDoc 命令:javadoc -encoding UTF-8 -charset UTF-8 Doc.java 执行该命令后,会在java目录生成index.html打开就可以看到生成的文档了 ...
- spring boot 通过feign调用api接口
目的:远程调用服务器api,直接上步骤: 1,添加maven依赖,这是必须的: <dependency> <groupId>org.springframework.cloud& ...
- 基于MATLAB的手写公式识别(2)
基于MATLAB的手写公式识别 图像的预处理(除去噪声.得到后续定位分割所需的信息.) 预处理其本质就是去除不需要的噪声信息,得到后续定位分割所需要的图像信息.图像信息在采集的过程中由于天气环境的影响 ...