237. Delete Node in a Linked List
2016-06-05 18:33
453 查看
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) { if(node==null){ return; } node.val = node.next.val; node.next = node.next.next; } }
相关文章推荐
- pomelo rpc调用出错的解决
- leetcode 19 Remove Nth Node From End of List C++
- C语言中Node * a,和Node* &a的区别
- task3--nodejs原生模块fs写一个web文件管理器
- 【Node.js】mongoose教程10--聚合(Aggregation)的应用
- 【Node.js】mongoose教程09--删除
- 【Node.js】mongoose教程08--更新
- 【Node.js】mongoose教程07--排重与计数
- 【Node.js】mongoose教程06--排序
- 【Node.js】mongoose教程05--查询
- 【Node.js】mongoose教程04--存储
- 【Node.js】mongoose教程03--Schema与Model
- 【Node.js】mongoose教程01--工程搭建
- 在Ubuntu上安装Node.js
- ubuntu搭建node.js+express
- Node学习笔记(三):基于socket.io web版你画我猜(一)
- nodejs(1)
- Angular + Node 生成 随机数
- Node.js之Express二
- node中的Stream-Readable和Writeable解读