(easy)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 that node.
Supposed the linked list is 1 -> 2 -> 3 -> 4
and you are given the third node with value 3
, the linked list should become 1 -> 2 -> 4
after calling your function.
思想:将要删除节点的下一个节点的值赋给要删除的节点,删除要删除节点的下一节点即可。
代码如下:
/**
* 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) {
ListNode nextNode=node.next;
node.val=nextNode.val;
node.next=nextNode.next; }
}
运行结果:
(easy)LeetCode 237.Delete Node in a Linked List的更多相关文章
- [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 ...
- leetcode 237 Delete Node in a Linked List python
题目: Write a function to delete a node (except the tail) in a singly linked list, given only access t ...
- 17.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 -David_Lin
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 删除链表结点(只给定要删除的结点) C++/Java
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_Easy tag: 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 ...
随机推荐
- 转载: scikit-learn学习之K最近邻算法(KNN)
版权声明:<—— 本文为作者呕心沥血打造,若要转载,请注明出处@http://blog.csdn.net/gamer_gyt <—— 目录(?)[+] ================== ...
- elipse 调试 反射 invoke 子类
真实案例: 调试一个接口,子类invoke的,结果断点断不到: 查找两个项目间的关联.依赖,无果. 问人吧,结果是配置文件没改成本机: #============================# # ...
- MYSQL 分组排名
今天遇到一个MYSQL排序的问题,要求按某列进行分组,组内进行排序. 百度一下发现MYSQL不支持row_number(),rank()等函数. 采用的办法如下,我们首先创建一个测试表: --创建表 ...
- mysql常用命令集锦
一.DCL语句(数据控制语句) 1.授权远程访问,针对IP和用户.DB的 grant {privilege list} on {dbname}.* to '{user}'@'{ip}' identif ...
- Android 使用Telephony API
Android 使用Telephony API public class TelephonyDemo extends Activity { TextView textOut; TelephonyMan ...
- java单例模式和双例模式
今天朋友找我给做道题,双例模式,我是没听说过,都说是单例模式和多例模式, 也不知道双例模式什么时候用,就简单写了一个案例,不知道对不对,个人感觉蛮对的,双例就是单例+单例,废话不说了!!!! /* * ...
- 【java】 java 实现mysql备份
使用java实现mysql的备份: public class MySQLBackUp { /** * Java代码实现MySQL数据库导出 * * @author GaoHuanjie * @para ...
- 项目ppt演讲与阶段性总结
☆车老师讲解PPT项目: 1.汉企0410天启网络公司 2.Ppt--画龙点睛 3.项目制作背景-->点到人心上,别一堆文字,别虚,点出1234 4.说话量化.具象化:明天下午5.00做完,做不 ...
- .NET去掉HTML标记
using System.Text.RegularExpressions; /// <summary> /// 去除HTML标记 /// </summary> /// < ...
- android学习笔记14——GridView、ImageSwitcher
GridView--网格视图.ImageSwitcher--图像切换器 ==> GridView,用于在界面上按行.列的分布形式显示多个组件:GridView和ListView父类相同——Abs ...