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 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.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
void deleteNode(ListNode* node) {
node->val = node->next->val; ListNode * temp = node->next;
node->next = temp->next;
free(temp);
}
};
237. Delete Node in a Linked List【easy】的更多相关文章
- Leet Code OJ 237. Delete Node in a Linked List [Difficulty: Easy]
题目: 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 ...
- 160. Intersection of Two Linked Lists【easy】
160. Intersection of Two Linked Lists[easy] Write a program to find the node at which the intersecti ...
- 206. Reverse Linked List【easy】
206. Reverse Linked List[easy] Reverse a singly linked list. Hint: A linked list can be reversed eit ...
- 234. Palindrome Linked List【easy】
234. Palindrome Linked List[easy] Given a singly linked list, determine if it is a palindrome. Follo ...
- [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 t ...
- 【一天一道LeetCode】#237. Delete Node in a Linked List
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...
随机推荐
- 【矩阵哈希】【哈希表】bzoj2351 [BeiJing2011]Matrix
引用题解:http://blog.csdn.net/popoqqq/article/details/41084047 #include<cstdio> #include<cstrin ...
- zk client获取数据
获取数据 它返回znode的关联数据和指定znode的元数据.你将获得信息,例如上次修改数据的时间,修改的位置以及数据的相关信息.此CLI还用于分配监视器以显示数据相关的通知. 语法 get /pat ...
- CSS3:animation动画
animation只应用在页面上已存在的DOM元素上,学这个不得不学keyframes,我们把他叫做“关键帧”. keyframes的语法法则: @keyframes flash { from{ le ...
- 关于spring-data-jpa的排序问题
本测试基于springBoot框架实现. pom.xml文件: <project xmlns="http://maven.apache.org/POM/4.0.0" xmln ...
- LVM分区管理和扩展
一.LVM简介 LVM是 Logical Volume Manager(逻辑卷管理)的简写.LVM将一个或多个硬盘的分区在逻辑上集合,相当于一个大硬盘来使用,当硬盘的空间不够使用的时候,可以继续将其它 ...
- iOS: Xcode7安装KSImageNamed插件,自动读取图片名称
官方文档: ## How do I use it? Build the KSImageNamed target in the Xcode project and the plug-in wil ...
- photo sphere viewer使用图像数据替代路径来生成全景图
photo sphere viewer是一个js库,用来将全景图片生成360度的全景图像,但是其要求传入的是个路径.如何使用数据代替路径生成图像. 我采用的方法是用img标签生成图像,然后调用img. ...
- JavaScript里面向对象的继承:不使用构造函数实现"继承"
一.什么是"非构造函数"的继承? //比如,现在有一个对象,叫做"中国人". var Chinese = { nation:'中国' }; //还有一个对象,叫 ...
- 1-N中1出现的次数
/*标记1-N中1出现的次数.例如,当N等于18时,1出现的次数为2 + 9 = 11 个位数出现1的为:1,11,十位数出现1的为10-18*/public class OneNoInN { // ...
- ActiveMQ Spring 集成配置
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-jms&l ...