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

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

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

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#-WebForm-ASP开发练习:从数据库中动态添加信息

    传统的ASP开发方式,是C#代码和HTML代码混合在一起,ASP与ASP.NET不是一个东西. <%  %>  -  可以扩起来一段范围,这一段范围之内只能允许编写C#代码 <%= ...

  2. UISearchBar控件-让我们来搞定!(转)

    转载自:http://blog.sina.com.cn/s/blog_7b9d64af0101dfg8.html     最近用到搜索功能.于是,经过不断的研究,终于,有点懂了. 那就来总结一下吧,好 ...

  3. python 之 PIP 安装

    1.安装的必备包 pip 和 setuptool 都要有, 这个可以从python.org网站下载 //  setuptool 安装  下载地址 https://pan.baidu.com/s/1gf ...

  4. React Native 开发之 (01) 配置开发环境

    一 React Native React Native 是由Facebook发布的开源框架,着力于提高多平台开发的开发效率 —— 仅需学习一次,编写任何平台.(Learn once, write an ...

  5. centos6 install mcrypt

    Download the latest epel-release rpm from http://dl.fedoraproject.org/pub/epel/6/x86_64/ Install epe ...

  6. photoshop拾色器如何恢复默认?

    今天在做设计图的时候,遇到一个问题,当时就把我给整蒙了. 问题是这样的,ps的调色器变成了这样,如下: 本来应该是这样: 可能有人已经看出两张图的不同之处了. 但是我当时忙的不得了,恩是不知道哪里除了 ...

  7. 创建16x16二级hash目录

    Hash目录是一种优化文件存储性能的方法.无论是Windows还是Linux,无论是NTFS还是ext4,每个目录下所能容纳的项目数是有限的.并不是不能保存,而是当项目数量过大的时候,会降低文件索引速 ...

  8. ypzl药品质量不合格数据库-excel自动排版

    原创: qq:231469242 import xlrdimport pandas,numpyimport matplotlib.pyplot as pltimport pandas as pd #参 ...

  9. 10月25日上午PHP继承多态

    概念:子类可以继承父类的一切 方法重写:在子类里面对父类的方法进行重写,实现自己独特的功能.特点:单继承:一个子类只能有一个父类,一个父类可以派生出多个子类.override重写(子类对父类的重写) ...

  10. 15个JavaScript本地存储技术的函数库和工具

    当构建更复杂的JavaScript应用程序运行在用户的浏览器是非常有用的,它可以在浏览器中存储信息,这样的信息可以被共享在不同的页面,浏览会话. 在最近的过去,这将有可能只被cookies文本文件保存 ...