237.Delete Node in a Linked List
2015-10-08 18:52
603 查看
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
with value
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.
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solution { /* * A->B->C * 想删除A,则把B的val赋值给A的val,然后把B->next赋值给A->next */ public void deleteNode(ListNode node) { ListNode post = node.next; node.val = post.val; node.next = post.next; } }
相关文章推荐
- 使用archiver在nodejs下打包
- node.js下when.js(Promises/A)的实践
- nodejs学习笔记---1
- Node.js安装配置
- Failed to connect to /XXXfor block, add to deadNodes and continue. java.net.NoRouteToHostException:
- Browserify - 像Node.js的require()一样组织浏览器端的js代码
- setTimeout,setInterval,process.nextTick,setImmediate in Nodejs
- nodejs中exports与module.exports的实践
- 构筑RubyMine IDE开发工具的Coffeescript+node.js开发环境(for windows)
- 安装node.js+express for windows的Web开发环境
- nodejs随记03
- Windows环境下的NodeJS+NPM+Bower安装配置
- [前端] nodejs之cookie入门
- jbpm node signal
- 阿里云ecs磁盘inodes满了
- nodejs随记02
- Node.js学习总结(一)
- Node.js开发入门—Buffer用法详解
- nodejs 设置API代理
- node.js 使用 UglifyJS2 高效率压缩 javascript 文件