Delete Node in a Linked List
2015-07-28 17:52
495 查看
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
the linked list should become
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 { public void deleteNode(ListNode node) { node.val = node.next.val; node.next = node.next.next; } }
相关文章推荐
- 我的第一个Node web程序
- Populating Next Right Pointers in Each Node
- Node.js笔记(十)Nodejs与DOM操作
- 【node.js】windows安装express:'express' 不是内部或外部命令,也不是可运行的程序或批处理文件。
- nodejs npm常用命令
- 最新nodejs的开发学习实战(1)从一个博客开始
- ask question on freenode IRC
- Node.Js —— PM2介绍
- NodeJs服务器管理
- Reverse Nodes in k-Group
- nodejs高大上的部署方式-PM2
- Node.js 究竟是什么?
- [leetcode-25]Reverse Nodes in k-Group(C)
- NameNode,SecondaryNameNode与Datanode文件详解
- Swap Nodes in Pairs
- LeetCode Reverse Nodes in k-Group 每k个节点为一组,反置链表
- nodeJs npm包发布
- nodeJs 制作全局命令
- Remove Nth Node From End of List
- nodeJs 使用npm把模块设置成全局命令后报错