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 ...
随机推荐
- add添加
s = {1,2,3,4,5,6,} 进行添加数据! s = {1,2,3,4,5,6,} s.add('s')#添加字符串's' s.add('3')#添加字符串'3' s.add(3)#添加3和字 ...
- [转]ExtJS之遍历Store
原文地址:http://blog.sina.com.cn/s/blog_67cc6e7d0100ox6u.html ExtJS中,一般很少需要遍历Store,因为它的selectModel很好用,无论 ...
- 无法加载父级样式或设置IIS的asp站点启用父路径
打开IIS 1.单击站点,在"IIS"区域中找到ASP图标,双击. 2.找到"启用父路径"项目,将对应的值设置为"TRUE"即可. 顶
- mosquitt win32
软件 mosquitto-1.4.10-install-win32.exe. 安装时候提示下载后面两个.win32openssl一定是1_0_1,否则没有需要的dll文件. pthreadVC2.dl ...
- Maven:将Jar安装到本地仓库和Jar上传到私服
1.依赖如下: <dependency> <groupId>org.quartz-scheduler.internal</groupId> <artifact ...
- 使用Pip安装distribute、nose、virtualenv
1 安装distribute sudo pip install distribute 2 安装nose sudo pip install nose 3 安装virtualenv sudo pip in ...
- 最新的jQuery插件和JavaScript库
每一个前端开发人员很清楚的重要性和功能的JavaScript库提供.它提供了一个简单的接口,用于构建快速动态的接口,而无需大量的代码. 谢谢你的超级从事jQuery开发者社区,人始终是创造新的和令人惊 ...
- FindWindowEx用法
函数原型:HWND FindWindowEx(HWND hwndParent,HWND hwndChildAfter,LPCTSTR lpszClass,LPCTSTR lpszWindow): 参数 ...
- WP8下实现刮刮乐(橡皮擦)功能
说到刮刮乐这个功能,我们最先想到的是上下两张(长方形)重叠,之后对上面这张图片进行操作. 我的想法是:通过手势,让手指划过的地方变成透明的,底部就会显示了. 那如何让图片变为透明呢?这就要对图片的像素 ...
- nginx:413 Request Entity Too Large 及 修改 PHP上传文件大小配置
开发环境:CentOS + Nginx + PHP + MySql + phpMyAdmin 在用 phpMyAdmin 进行 sql 数据库导入的时候,经常需要上传比较大的 sql 数据文件,而这时 ...