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 ...
随机推荐
- $《第一行代码:Android》读书笔记——第10章 Android网络编程
(一)WebView的用法 1.WebView也是一个普通的控件. 2.常用用法: WebView webView = (WebView)findViewById(R.id.web_view); we ...
- Adding Flexcan driver support on Kernel
Adding Flexcan driver support on Kernel On kernel menuconfig, add the following items: [*] Networkin ...
- 一个骑行者的独白,很不错,我就转载了。--原名是--<<关于认怂这件事>>
一个骑行者的独白,很不错,我就转载了.--原名是--<<关于认怂这件事>> PS:我不知道这些是对是错,但都不曾后悔,或许哪天我在生活面前也怂了,然后跑回大城市乖乖的当个小 ...
- jquery图片过滤归类应用
在线演示 本地下载
- PHP类的变量与成员,及其继承、访问与重写要注意的问题
PHP的类及其实例: <?php ?> 后期静态绑定:为了避免子类重写静态属性后,使用继承来的方法仍然方法父类的静态属性,PHP5.3增加了一个新的语法,后期静态绑定,使用static关 ...
- 20145230《Java程序设计》第3周学习总结
20145230 <Java程序设计> 第3周学习总结 教材学习内容总结 String s=new String();第四章我首先了解了CPU与内存的关系,栈与堆的关系.要产生对象必须先定 ...
- 在unity 中,使用http请求,下载文件到可读可写路径
在这里我用了一个线程池,线程池参数接收一个带有object参数的,无返回值的委托 ,下载用到的核心代码,网上拷贝的,他的核心就是发起一个web请求,然后得到请求的响应,读取响应的流 剩下的都是常见的I ...
- Kubernetes Metrics-Server
github地址:https://github.com/kubernetes-incubator/metrics-server 官网介绍:https://kubernetes.io/docs/task ...
- keepalived检测脚本及注意事项
keepalived检测脚本的作用及注意事项: 默认每隔3秒钟执行一次检测脚本,检查nginx服务是否启动,如果没启动就把nginx服务启动起来,如果启动不成功,就把keepalived服务down掉 ...
- poj 3126 Bfs
Prime Path Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14539 Accepted: 8196 Descr ...