237 Delete Node in a Linked List 删除链表的结点
编写一个函数,在给定单链表一个结点(非尾结点)的情况下,删除该结点。
假设该链表为1 -> 2 -> 3 -> 4 并且给定你链表中第三个值为3的节点,在调用你的函数后,该链表应变为1 -> 2 -> 4。
详见:https://leetcode.com/problems/delete-node-in-a-linked-list/description/
Java实现:
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public void deleteNode(ListNode node) {
node.val=node.next.val;
node.next=node.next.next;
}
}
C++实现:
/**
* 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 *tmp=node->next;
node->next=tmp->next;
delete tmp;
}
};
237 Delete Node in a Linked List 删除链表的结点的更多相关文章
- 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 删除链表的节点
		
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 删除链表中的节点
		
https://leetcode-cn.com/problems/delete-node-in-a-linked-list/ 非常巧妙的一道题. 题目没有给head,心想没有head我怎么才能找到要删 ...
 - [CareerCup] 2.3 Delete Node in a Linked List 删除链表的节点
		
2.3 Implement an algorithm to delete a node in the middle of a singly linked list, given only access ...
 - [LeetCode] 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 ...
 - 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 ...
 - 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【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 ...
 
随机推荐
- Thinkphp5.0 的Model模型
			
Thinkphp5.0 的Model模型 新建user模型User.php: <?php namespace app\index\model; use think\Model; class Us ...
 - jquery判断单选按钮radio是否选中的方法
			
JQuery控制radio选中和不选中方法总结 一.设置选中方法 复制代码代码如下: $("input[name='名字']").get(0).checked=true; $(&q ...
 - mysql的时间戳说白了就俩问题,自动更新问题和不自动更新问题
			
mysql的时间戳timestamp说白了就俩问题,自动更新问题和不自动更新问题
 - 我的arcgis培训照片4 来自http://www.cioiot.com/successview-549-1.html
 - Telnet登入cisco router 1800
			
Login to Router and change to privileged modec:\>telnet 192.168.6.1Trying 192.168.6.1...Connected ...
 - 【剑指Offer】俯视50题之31 - 40题
			
面试题31连续子数组的最大和 面试题32从1到n整数中1出现的次数 面试题33把数组排成最小的数 面试题34丑数 面试题35第一个仅仅出现一次的字符 面试题36数组中的逆序对 面试题37两个链表的第一 ...
 - android 获取手机信息工具类
			
package com.yqy.yqy_listviewheadview; import android.content.Context; import android.telephony.Telep ...
 - 浅析分布式数据库中间件DDM
			
前言 DDM是什么?这是华为云Paas推出的分布式数据库中间件,DDM(Distributed Database Middleware)是一个实现了Mysql协议栈的服务器,前端用户可以把它看做一个数 ...
 - Flex 页面启动事件
			
事件启动顺序 容器Preinitialize=>子组件preinitialize=>子组件initialize=>childAdd=>initialize =>子组件cr ...
 - IE7下兼容问题总结
			
1.<LI> border-bottom 不显示 解决办法 加个height:100%; 2.border:none;不好使,要用 border:0;