leetcode:Delete Node in a Linked List 【Java】
2016-03-09 22:56
639 查看
一、问题描述
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
二、问题分析
原地删除链表结点。
三、算法代码
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 -> 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) { ListNode nextNode = null; nextNode = node.next; if (nextNode != null) { node.val = nextNode.val; node.next = nextNode.next; } } }
相关文章推荐
- [nodejs] nodejs开发个人博客(四)数据模型
- AngularJS+Node的RESTful之基本实现
- 我的Node.js处女作
- 19. Remove Nth Node From End of List
- C++与Nodejs的交互
- 【nodejs】服务器处理url请求并返回json数据
- webstorm+nodejs+JetBrains IDE Support+chrome打造前端开发神器
- Nodejs如何复制文件
- nodejs设置NODE_ENV环境变量
- ztree addNode editName removeNode
- 【JavaScript】ReactJS&NodeJS了解资料
- Leetcode:Swap Nodes in Pairs 单链表相邻两节点逆置
- 19. Remove Nth Node From End of List
- 记 Ubuntu14.04 Monodevelop 安装的两个问题
- nodejs及bigpipe技术初探
- Nodejs模块化
- 为什么我要用 Node.js
- [LeeCode]116. Populating Next Right Pointers in Each Node
- leetcode刷题(19. Remove Nth Node From End of List)
- 利用nodeJs来安装less以及编译less文件为css文件