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】的更多相关文章

  1. 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 ...

  2. 【LeetCode】237. Delete Node in a Linked List 解题报告 (Java&Python&C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 设置当前节点的值为下一个 日期 [LeetCode] ...

  3. 451. Swap Nodes in Pairs【LintCode java】

    Description Given a linked list, swap every two adjacent nodes and return its head. Example Given 1- ...

  4. 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 ...

  5. 245. Subtree【LintCode java】

    Description You have two very large binary trees: T1, with millions of nodes, and T2, with hundreds ...

  6. 445. Cosine Similarity【LintCode java】

    Description Cosine similarity is a measure of similarity between two vectors of an inner product spa ...

  7. 433. Number of Islands【LintCode java】

    Description Given a boolean 2D matrix, 0 is represented as the sea, 1 is represented as the island. ...

  8. 423. Valid Parentheses【LintCode java】

    Description Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine ...

  9. 422. Length of Last Word【LintCode java】

    Description Given a string s consists of upper/lower-case alphabets and empty space characters ' ', ...

随机推荐

  1. HDU 1009 FatMouse' Trade(简单贪心)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...

  2. ARM v8-A 系列CPU的MMU隐射分析

    ARM v8-A 系列CPU的MMU隐射分析 摘要:V8-A系列CPU有ELX,X为0~3等4个异常级别,又有AArch64和AArch32两种执行状态,异常级别可以决定执行状态,而对应着执行状态,M ...

  3. Lua中的数据结构

    1 数组:(lua习惯数组从1开始) a={} , do a[i]= end 2 阵和多维数组 : mt={}//新建一个表,表元素为表 ,N do mt[i]={}//新建一个表,里面的表元素为值 ...

  4. Android 发版的小工具

    Android加固包签名 我们知道自己的apk在上传市场的时候, 为了更好的包含我们的代码需要加固服务, 加固后的apk是不能直接安装的, 需要我们手动签名. 关于Android签名的知识就不在赘述了 ...

  5. ORACLE中查询语句的执行顺及where部分条件执行顺序测试

    Oracle中的一些查询语句及其执行顺序 原文地址:https://www.cnblogs.com/likeju/p/5039115.html 查询条件: 1)LIKE:模糊查询,需要借助两个通配符, ...

  6. 微信小程序 | 未来O2O电商的“阴谋”

    发展历史 2016年1月11日,微信之父张小龙时隔多年的公开亮相,提出了公众号服务的短板,而透露微信内部正在研发的新形态工具,称之"微信小程序". 2016年9月21日,微信小程序 ...

  7. python 输入三个整数,按照从小到大的顺序打印

    # # 3 输入三个整数,按照从小到大的顺序打印 a = int(input('请输入第一个整数:')) b = int(input('请输入第二个整数:')) c = int(input('请输入第 ...

  8. 原生 JS 实现扫雷 (分析+代码实现)

    阅读这篇文章需要掌握的基础知识:Html5.CSS.JavaScript 在线Demo:查看 扫雷规则 在写扫雷之前,我们先了解下它的游戏规则 ● 扫雷是一个矩阵,地雷随机分布在方格上. ● 方格上的 ...

  9. hibernate-笔记

    什么是 hibernate 框架 1.hibernate 框架应用在 javaee 三次结构中 dao 层框架 2.在dao 层里面对数据库做curd 操作, 使用hibernate 做crud 操作 ...

  10. 自己花了2天时间,重新整理了个全面的vue2的模板

    自己花了2天时间,重新整理了个全面的vue2的模板,基本vue中需要的部分都整理封装好了,希望大家喜欢^ ^.欢迎大家star或者fork呀~,https://github.com/qianxiaon ...