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 ' ', ...
随机推荐
- STM32之关闭JTAG
1.有些时候不想用JTAG口(而用SWJ在线调试),把JTAG暂用的IO通过remap出来使用 2.比如48 pin的STM32F103CBT6单片机: GPIO_PinRemapConfig(GPI ...
- 轻量ORM-SqlRepoEx (十一)扩展
以下为 SqlRepoEx.MsSql.ServiceCollection 代码 public static IServiceCollection AddSqlRepo(this IServiceCo ...
- 10 OCP知识点讲解 之 什么是Buffer Cache?
OCP知识点讲解 之 什么是Buffer Cache? 分类: Oracle 2012-06-22 17:36:54 一.Buffer cache作用: Buffer cache是Oracle建立 ...
- [翻译]Hystrix wiki–How it Works
注:本文并非是精确的文档翻译,而是根据自己理解的整理,有些内容可能由于理解偏差翻译有误,有些内容由于是显而易见的,并没有翻译,而是略去了.本文更多是学习过程的产出,请尽量参考原官方文档. 流程图 下图 ...
- Spring : JPA的单独使用
title: 如何单独使用spring data jpa 引用pom文件: <dependency> <groupId>org.springframework.data< ...
- 20190118-利用Python实现Pig Latin游戏
1.利用Python实现Pig Latin字母游戏 “Pig Latin”是一个英语儿童文字改写游戏,整个游戏遵从下述规则:a. 元音字母是‘a’.‘e’.‘i’.‘o’.‘u’.字母‘y’在不是第一 ...
- python爬虫#数据存储#JSON/CSV/MYSQL/MongoDB/
Json数据处理 JSON支持数据格式: 对象(字典).使用花括号. 数组(列表).使用方括号. 整形.浮点型.布尔类型还有null类型. 字符串类型(字符串必须要用双引号,不能用单引号). 多个数据 ...
- python学习——初始面向对象
一.讲在前面 编程的世界中有三大体系,面向过程.面向函数和面向对象编程.而面向过程的编程就包括了面向函数编程,接下来说一下面向对象.假如 ,你现在是一家游戏公司的开发人员,现在需要你开发一款叫做< ...
- python学习笔记:第18天 面向对象04-反射
目录 issubclass和isinstance 区分函数和方法 反射 issubclass和isinstance issubclass:可以判断一个类是否另一个类的子类. # issubclass ...
- python3 package management 包管理 实例
包是一种组织管理代码的方式,包里面存放的是模块 用于将模块包含在一起的文件夹就是包 包内包含__init__.py标志性文件 定义一个学生类,一个sayhello函数,一个打印语句 # p01.py ...