------------------------------------------------

因为不知道前序是谁,所以只好采用类似于数组实现的列表移动值,

又因为如果当前是最后一个元素了但是已经没办法修改前序了所以必须在倒数第二个就修改,所以应该提前进行判断

AC代码:

/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public class Solution {
public void deleteNode(ListNode node) {
if(node==null) return ;
if(node.next!=null && node.next.next==null){
node.val=node.next.val;
node.next=null;
return;
}
node.val=node.next.val;
deleteNode(node.next);
}
}

题目来源: https://leetcode.com/problems/delete-node-in-a-linked-list/

LeetCode之237. Delete Node in a Linked List的更多相关文章

  1. 【一天一道LeetCode】#237. Delete Node in a Linked List

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...

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

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

  3. 【LeetCode】237. Delete Node in a Linked List

    题目: Write a function to delete a node (except the tail) in a singly linked list, given only access t ...

  4. LeetCode Javascript实现 283. Move Zeroes 349. Intersection of Two Arrays 237. Delete Node in a Linked List

    283. Move Zeroes var moveZeroes = function(nums) { var num1=0,num2=1; while(num1!=num2){ nums.forEac ...

  5. 237. Delete Node in a Linked List(C++)

    237. Delete Node in a Linked Lis t Write a function to delete a node (except the tail) in a singly l ...

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

  7. [LeetCode] 237. Delete Node in a Linked List 解题思路

    Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...

  8. LeetCode 237. Delete Node in a Linked List (在链表中删除一个点)

    Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...

  9. [LeetCode] 237. Delete Node in a Linked List 删除链表的节点

    Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...

随机推荐

  1. C语言初级进阶1

    1.数据类型1.1.基本数据类型数据类型分2类:基本数据类型+复合类型基本类型:char short int long float double复合类型:数组 结构体 共用体 类(C语言没有类,C++ ...

  2. 利用phpize 外挂php扩展

    如果你的php是手动编译安装的 ,可能有一些扩展一开始并没有开启,以后需要某扩展的时候又不想重新编译php,使用phpize可以动态添加扩展 以Ubuntu为例, 如果你是我这样安装php的  apt ...

  3. java-图片下载

    图片下载 public static void main(String[] args) { List<String> urlList = new ArrayList<String&g ...

  4. 【Matplotlib】详解图像各个部分

    首先一幅Matplotlib的图像组成部分介绍. 在matplotlib中,整个图像为一个Figure对象.在Figure对象中可以包含一个或者多个Axes对象.每个Axes(ax)对象都是一个拥有自 ...

  5. cocos2d-x打飞机实例总结

    写了一个cocos2d-x的打飞机游戏,为了深入了解,准备进入引擎内部,深入分析一下打飞机,顺便梳理一下相关的知识 打算分为几个部分: 1.程序入口和场景切换模块分析:简单了解HelloWorld怎样 ...

  6. mysql日期格式化

    DATE_FORMA T(date, format) 根据格式串format 格式化日期或日期和时间值date,返回结果串. 可用DATE_FORMAT( ) 来格式化DATE 或DATETIME 值 ...

  7. 【原】理解javascript中的闭包

    闭包在javascript来说是比较重要的概念,平时工作中也是用的比较多的一项技术.下来对其进行一个小小的总结 什么是闭包? 官方说法: 闭包是指有权访问另一个函数作用域中的变量的函数.创建闭包的常见 ...

  8. 《Python核心编程》18.多线程编程(三)

    18.6使用threading模块 #!/usr/bin/env python # -*- coding:utf-8 -*- """从Thread类中派生出一个子例,创建 ...

  9. Web开发技术发展历史

    Web开发技术发展历史   来自:天码营 原文:http://www.tianmaying.com/tutorial/web-history Web的诞生 提到Web,不得不提一个词就是"互 ...

  10. CSS3中的动画功能(二)

    上一篇文章讲解了css3动画中的一个即transitions,那么今天来说说另外一个animations.和transitions不同的是animations可以定义多个关键帧以及每个关键帧中元素的属 ...