372. Delete Node in a Linked List【LintCode java】
Description
Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.
Example
Linked list is 1->2->3->4
, and given node 3
, delete the node in place 1->2->4
解题:删除指定的结点。由于java没有delete 或者 free,如果要要删除的结点是最后一个节点,在不知道头结点的情况下,是不能删除的。代码如下:
- /**
- * Definition for ListNode.
- * public class ListNode {
- * int val;
- * ListNode next;
- * ListNode(int val) {
- * this.val = val;
- * this.next = null;
- * }
- * }
- */
- public class Solution {
- /*
- * @param node: the node in the list should be deletedt
- * @return: nothing
- */
- public void deleteNode(ListNode node) {
- // write your code here
- if(node == null || node.next == null)
- return;
- node.val = node.next.val;
- node.next = node.next.next;
- return;
- }
- }
372. Delete Node in a Linked List【LintCode java】的更多相关文章
- 237. Delete Node in a Linked List【easy】
237. Delete Node in a Linked List[easy] Write a function to delete a node (except the tail) in a sin ...
- 【LeetCode】237. Delete Node in a Linked List 解题报告 (Java&Python&C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 设置当前节点的值为下一个 日期 [LeetCode] ...
- 451. Swap Nodes in Pairs【LintCode java】
Description Given a linked list, swap every two adjacent nodes and return its head. Example Given 1- ...
- 376. Binary Tree Path Sum【LintCode java】
Description Given a binary tree, find all paths that sum of the nodes in the path equals to a given ...
- 245. Subtree【LintCode java】
Description You have two very large binary trees: T1, with millions of nodes, and T2, with hundreds ...
- 445. Cosine Similarity【LintCode java】
Description Cosine similarity is a measure of similarity between two vectors of an inner product spa ...
- 433. Number of Islands【LintCode java】
Description Given a boolean 2D matrix, 0 is represented as the sea, 1 is represented as the island. ...
- 423. Valid Parentheses【LintCode java】
Description Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine ...
- 422. Length of Last Word【LintCode java】
Description Given a string s consists of upper/lower-case alphabets and empty space characters ' ', ...
随机推荐
- ETL测试小结
一.ETL测试的重要性: ETL(Extract-Transform-Load的缩写,即数据抽取.转换.装载的过程)作为BI/DW(Business Intelligence)的核心和灵魂,能够按照统 ...
- 设置UI控件的Layer属性(边框可见,边框颜色,边框宽度,边框圆角)
设置UI控件的Layer属性 #import "ViewController.h" @interface ViewController () @property (strong, ...
- SSM项目之电商项目easymall(一)
一 环境准备 软件环境: 1 jdk1.8 JAVA_HOME:是给软件用的,各种启动的软件都会寻找JAVA_HOME的环境变量: Path:给windows用的: ...
- etcd部署说明
etcd是一个K/V分布式存储,每个节点都保存完成的一份数据.有点类似redis.但是etcd不是数据库. 1.先说废话.之所以会用etcd,并不是实际项目需要,而是前面自己写的上传的DBCacheS ...
- 02 看懂Oracle执行计划
看懂Oracle执行计划 最近一直在跟Oracle打交道,从最初的一脸懵逼到现在的略有所知,也来总结一下自己最近所学,不定时更新ing… 一:什么是Oracle执行计划? 执行计划是一条查询语句在 ...
- iOS开发学习资源
最近想写点关于iOS开发的总结和心得.虽然网上资源一大堆,质量参差不齐,还是推荐一点干货吧! https://www.objc.io/issues/ 这个网站的文章质量很高,很多干货,可惜今年已经停 ...
- LAMP+Varnish的实现
基于Keepalived+Varnish+Nginx实现的高可用LAMP架构 注意:各节点的时间需要同步(ntpdate ntp1.aliyun.com),关闭firewalld(systemctl ...
- 分布式缓存 Redis(二)
代码实例 namespace RedisTest { class Program { static void Main(string[] args) { Student stu = RedisOper ...
- 【Hadoop故障处理】全分布下,DataNode进程正常启动,但是网页上不显示,并且DataNode节点为空
[故障背景] DataNode进程正常启动,但是网页上不显示,并且DataNode节点为空. /etc/hosts 的ip和hostname配置正常,各个机器之间能够ping通. [日志错误信息] ...
- laravel 安装添加多站点
官方文档如下 https://learnku.com/laravel/t/1160/laravel-nginx-multi-site-configuration