[刷题] 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 ...
随机推荐
- SQL 存储过程里调用另一个存储过程
由于创建了一个存储过程,并且要在另一个存储过程里调用这个存储过程所以在网上找了一下相关的代码,现在总结一下,防止以后还会用到 由于这次我写的存储过程只需要返回一个求和的结果,所以我使用了output ...
- 第30 章 : 理解 RuntimeClass 与使用多容器运行时
理解 RuntimeClass 与使用多容器运行时 本文将主要分享以下三方面的内容: RuntimeClass 需求来源 RuntimeClass 功能介绍 多容器运行时示例 RuntimeClass ...
- 设计原则:单一职责(SRP)原则
1 什么是单一职责(SRP)原则 单一职责原则的英文是 Single Responsibility Principle,缩写为 SRP.翻译过来就是:一个类或者模块只负责完成一个职责(或者功能). 所 ...
- Python数据分析入门(十七):绘制条形图
条形图的绘制方式跟折线图非常的类似,只不过是换成了plt.bar方法.plt.bar方法有以下常用参数: x:一个数组或者列表,代表需要绘制的条形图的x轴的坐标点. height:一个数组或者列表,代 ...
- 死磕Spring之AOP篇 - Spring AOP总览
该系列文章是本人在学习 Spring 的过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring 源码分析 GitHub 地址 进行阅读. Spring 版本:5.1 ...
- Numpy 对于矩阵的操作持续更新
>>> import numpy as np >>> a = np.random.randint(10,size=(5,5)) >>> a arr ...
- 本地+分布式Hadoop完整搭建过程
1 概述 Hadoop在大数据技术体系中极为重要,被誉为是改变世界的7个Java项目之一(剩下6个是Junit.Eclipse.Spring.Solr.HudsonAndJenkins.Android ...
- JavaFX获取屏幕尺寸
1 awt Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); double width = screenSize. ...
- 数据结构之队列(JavaScript描述)
队列数据结构 队列遵循先进先出原则的一组有序的项.对可在尾部添加新元素并从顶部移除元素.最新添加的元素必须排在队列的末尾 队列类似栈的例子 创建队列 创建一个类表示队列 队列内应该有一些方法 添加 ...
- 【网络协议】OSI七层模型 和TCP/IP五层模型
OSI(Open System Interconnection)七层模型 TCP/IP 五层模型