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. 浅谈DB2在线分析处理函数

    最近碰到一个测试需求,使用到了在线分析处理(OLAP),现总结记录一下,也希望能帮到有相关问题的朋友. 1. 测试环境是DB2,通过ETL(数据抽取,数据转换,数据加载)技术将数据源数据加载到目标数据 ...

  2. TextView selector 在LinearLayout中获取焦点问题

    通常需要修改textview被选中时文字颜色,总是没效果,有以下几种方式可以实现: <?xml version="1.0" encoding="utf-8" ...

  3. UVALive4682 XOR Sum

    UVALive4682 XOR Sum 题意 给定一个数组, 求连续子序列中异或值最大的值. 题解 假设答案区间为 [L, R], 则答案为 XOR[L, R], 可以将区间分解为 XOR[L,R] ...

  4. ARM 汇编指令集 特点之一:条件执行后缀

    mov r0,r1; moveq r0,r1;//这句代码是否执行 取决于 上几句代码 的运行结果(最后一次CPSR 寄存器 的 高四位   NZCV 的标志位) 条件后缀执行特点:1.条件后缀执行是 ...

  5. C# Console类的方法使用总结

    Console类表示控制台应用程序的标准输入流.输出流和错误流. 此类不能被继承,而在Java中,类似的功能则由System.in和System.out来实现了. 一 输出到控制台 输出到控制台就是把 ...

  6. javascript根据文件字节数返回文件大小

    function getFileSize(fileByte) { var fileSizeByte = fileByte; var fileSizeMsg = ""; if(fil ...

  7. 【模板】BM算法(找线性规律万能模板)

    (1) n是指要找该数列的第n项. (2) 往vec中放入该数列前几项的值,越多越精确. #include<set> #include<cmath> #include<v ...

  8. C# 后台Http访问 raw from 键值对

    using RestSharp;using System;using System.Collections;using System.Collections.Generic;using System. ...

  9. 多用户OFDM系统资源分配研究

    首先,OFDMA 是什么? OFDM 技术的基本原理是将无线信道划分为若干互相正交的子信道,把高速串行数据流转化为低速并行子数据流,低速并行子数据流在子信道上独立传输. OFDMA 是LTE的下行多址 ...

  10. JQuery制作网页—— 第七章 jQuery中的事件与动画

    1. jQuery中的事件: ●和WinForm一样,在网页中的交互也是需要事件来实现的,例如tab切换效果,可以通过鼠标单击事件来实现 ●jQuery事件是对JavaScript事件的封装,常用事件 ...