LeetCode OJ: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) {
if(node == NULL) return;
node->val = node->next->val;
node->next = node->next->next;
}
};
没什么好说的,下面是java版本的:
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public class Solution {
public void deleteNode(ListNode node) {
node.val = node.next.val;
node.next = node.next.next;
}
}
LeetCode OJ:Delete Node in a Linked List(链表节点删除)的更多相关文章
- Leetcode 237 Delete Node in a Linked List 链表
如题 删除是要注意让现在的链表等于下一个链表的值 class Solution { public: void deleteNode(ListNode* node) { ListNode *nextno ...
- [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 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 to th ...
- (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 ...
- 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 ...
- Java [Leetcode 273]Delete Node in a Linked List
题目描述: Write a function to delete a node (except the tail) in a singly linked list, given only access ...
- 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 ...
- 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 ...
- [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 ...
随机推荐
- ASP.NET MVC string赋值Html格式在显示View问题总结
ViewBag.Content = "<p>你好</p>"; string 类型的赋值一个 "<h1>你好</h1>&qu ...
- classmethod和staticmethod区别
实例方法:在类中,定义的方法,这个方法的第一个参数默认是实例对象,一般习惯使用self 类方法:在类中,定义的方法,这个方法的第一个参数默认是类对象,一般习惯用cls表示,用@classmethod装 ...
- HTML中表格的使用
表格: <table></table>表格 width:宽度.可以用像素或百分比表示. 常用960像素. border:边框,常用值为0. cellpadding:内容跟边框的 ...
- 微信小程序相关资料整理
微信小程序官方介绍https://mp.weixin.qq.com/debug/wxadoc/introduction/index.html?t=201818 微信小程序开发资源https://jue ...
- 前端之CSS样式
一.CSS 1.什么是CSS 层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的 ...
- Centos系统 上下文切换的检查思路
1.什么是上下文切换(Context Switch)? 上下文切换,有时也称做进程切换或任务切换,是指CPU从一个进程或线程切换到另一个进程或线程. 操作系统可以同时运行多个进程, 然而一颗CPU同时 ...
- Windos Server 2008 Tomcat 安装
web服务:apache-tomcat-7.0.75环境:jdk-7u80-windows-i586 1.安装jdk环境包 2.配置环境变量--> 环境变量--> 新建W --> 变 ...
- AngularJs 的一则错误 [$INJECTOR:MODULERR]
Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to: Error: [$injector:modu ...
- cocos2dx打飞机项目笔记四:Enemy类和EnemyLayer类
Enemy类没什么内容,就create和init方法,根据参数来创建不同的敌机,头文件代码如下: //飞机的类型 enum planeType {smallPlane, midPlane, bigPl ...
- UVA 580 Critical Mass (两次dp)
题意:一个字符串有n个位置每个位置只可能是L或者U,问你在所有可能出现的字符串中最少出现一次三个U连在一起的字符串的个数 题解:首先从左向右枚举每个位置i,保证i,i+1,i+2是U,并且i+2(不包 ...