leetcode 237. Delete Node in a Linked List
2016-07-21 17:43
591 查看
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
Subscribe to see which companies asked this question
思考:无
/**
* 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;
}
}
Supposed the linked list is
1 -> 2 -> 3 -> 4and you are given the third node with value
3, the linked list should become
1 -> 2 -> 4after calling your function.
Subscribe to see which companies asked this question
思考:无
/**
* 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;
}
}
相关文章推荐
- JavaScript之childNodes属性、nodeType属性学习
- Windows下从零开始学习nodejs4.X+express4.X开发--目录
- Windows下从零开始学习nodejs4.X+express4.X开发--(4)NPM
- Windows下从零开始学习nodejs4.X+express4.X开发--(3)创建服务器
- nodejs--path
- Windows下从零开始学习nodejs4.X+express4.X开发--(1)nodejs安装
- Windows下从零开始学习nodejs4.X+express4.X开发--(2)nodejs交互环境
- Node.js 调试 GC 以及内存暴涨的分析
- nodejs代码封装基础
- nodejs--fs模块
- nodejs留言板的一些总结
- 使用Node.js+Socket.IO搭建WebSocket实时应用
- 配置gulpfile文件,实现文件更改后浏览器即时刷新
- nodejs-- npm模块管理器
- nodejs安装和使用简单入门
- ubuntu下nvm,node以及npm的安装与使用
- nodejs--package
- Hadoop DataNode, NameNode无法启动
- Windows环境下的NodeJS+NPM+Bower安装配置步骤
- Nodejs异步流程控制Async