LeetCode之237. Delete Node in a Linked List

------------------------------------------------
因为不知道前序是谁,所以只好采用类似于数组实现的列表移动值,
又因为如果当前是最后一个元素了但是已经没办法修改前序了所以必须在倒数第二个就修改,所以应该提前进行判断
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的更多相关文章
- 【一天一道LeetCode】#237. Delete Node in a Linked List
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...
- 【LeetCode】237. Delete Node in a Linked List 解题报告 (Java&Python&C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 设置当前节点的值为下一个 日期 [LeetCode] ...
- 【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 ...
- 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 ...
- 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 ...
- 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 解题思路
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- 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 ...
- [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 ...
随机推荐
- Eclipse+maven创建webapp项目<二>(转)
原文地址:http://www.cnblogs.com/candle806/p/3439469.html 1.开启eclipse,右键new-->other,如下图找到maven project ...
- Linux下压缩音频文件
安装工具 sudo apt-get install lame 具体用法可以查看帮助 lame --help 通过更改音频文件的帧数 可以让文件变小 但是音质也会随之下降 现在比较多的mp3文件是1 ...
- 【poj1742】 Coins
http://poj.org/problem?id=1742 (题目链接) 题意 给出n钟纸币,每种纸币面值为a[i],数量为c[i],问能够成多少数值小于等于m的数. Solution 先想到了容斥 ...
- WPF基础到企业应用系列6——布局全接触
本文转自:http://knightswarrior.blog.51cto.com/1792698/365351 一. 摘要 首先很高兴这个系列能得到大家的关注和支持,这段时间一直在研究Windows ...
- HTTP协议 -- 认清协议常用状态码
HTTP协议作为web服务的基础,理所应当受到重视,但是周围的同事能够讲清楚HTTP协议的凤毛麟角.既然是基础,就应该早一点掌握,所以近半年(2016-2月——2016年6月),不准备学习新技术了.首 ...
- [转载]用 grub2 启动 clover.iso 来启动 OS X
这个帖子只用来解决特定问题,是楼主这两天辛苦的结晶,如果你遇到了跟我差不多的情形,你就可以尝试这个解决方案. 特定情景:1.不管你的机器支不支持 UEFI ,反正你现在是用传统 BISO + MBR ...
- 10月30日上午MySQL数据库的修改(从网页上实现对数据库的更改)
从网页页面上对数据库进行更改,连接着之前做的增加.删除.查询. 1.先做一个修改页面 <body> <!--这个页面需要让用户看到一些数据,所以不是一个纯php页面,页面效果和增加页 ...
- React.js入门笔记
# React.js入门笔记 核心提示 这是本人学习react.js的第一篇入门笔记,估计也会是该系列涵盖内容最多的笔记,主要内容来自英文官方文档的快速上手部分和阮一峰博客教程.当然,还有我自己尝试的 ...
- thinkphp3.2与phpexcel解析
1.impot导入 第一种方式: import("Org.Util.PHPExcel.TextT"); $tt = new \TextT(); //创建PHPExcel对象,注意, ...
- 三列等高 css实现
实现这个三列等高 布局需要最外层的一个div wrap容器 里面有三个div容器 这个最外层div 需要移除隐藏 overflow:hidden; 关键点就是三列div 同时margin-botto ...