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 ' ', ...
随机推荐
- Jmeter--JDBC请求(sqlserver)
做JDBC请求,首先要了解这个JDBC对象是什么,然后寻找响应的数据库连接URL和数据库驱动. 数据库URL:jdbc:sqlserver://200.99.197.190:1433;database ...
- 使用Kubespray部署Kubernetes集群
转载请标明出处: http://blog.csdn.net/forezp/article/details/82730382 本文出自方志朋的博客 Kubespray是Google开源的一个部署生产级别 ...
- NLP语言模型
语言模型: I. 基本思想 区别于其他大多数检索模型从查询到文档(即给定用户查询,如何找出相关的文档), 语言模型由文档到查询,即为每个文档建立不同的语言模型,判断由文档生成用户查 询的可能性有多大, ...
- Ubuntu 16.04 搭建 ELK
1.安装Java JDK sudo apt-get install default-jdk 2.安装Elasticsearch 1.导入Elasticsearch的GPG公钥 wget -qO - h ...
- cut 的用法
cut 文件内容查看 显示行中的指定部分,删除文件中指定字段 显示文件的内容,类似于下的type命令. 说明 该命令有两项功能,其一是用来显示文件的内容,它依次读取由参数file所指明的文件,将它们的 ...
- BUG-jQuery提交表单submit方法-TypeError: e[h] is not a function
问题:button按钮设置id为submit后,表单jquery.submit()无法提交,报告异常TypeError: e[h] is not a function 源码: 解决:参考http:// ...
- Lavavel5.5源代码 - RedisQueue是怎么实现
队列的基本功能: 1.立即执行:yes 2.延迟执行:yes 3.保证至少执行一次:yes 4.必须执行且最多执行一次:no 用到的数据结构: list.Sorted sets 延迟执行的机制: 1. ...
- day 22 内置的模块
1.简单的理解模块 写的每一个py文件都是一个模块,还有一些是我们一直在使用的模块. buildins: 内置模块. print, input random 主要是和随机相关的内容: ...
- HTTP学习之URL与资源
URL是因特网资源的标准化名称,该字符串指向一条电子信息片段,定义服务端应用程序在什么位置以及客户端要如何与其交互 一条完整的URL由多个片段组成. 通用URL组件 方案 以哪种协议访问服务器 用户 ...
- avast:中兴手机预装恶意软件 嵌入固件底层
著名安全机构 avast 发布报告称,旗下安全威胁实验室发现,中兴.爱可视.MyPhone 等厂商的多款安卓手机居然预装了恶意广告软件.该恶意软件被命名为“ Cosiloon ”,它会在用户使用浏览器 ...