9. 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.
Subscribe to see which companies asked this question
难度:easy
思路:将后面节点的值交换到前面
/**
* 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) {
if(node!=NULL)
{
node->val = node->next->val;
node->next = node->next->next;
}
}
};
9. Delete Node in a Linked List的更多相关文章
- 【4_237】Delete Node in a Linked List
Delete Node in a Linked List Total Accepted: 48121 Total Submissions: 109297 Difficulty: Easy Write ...
- Leetcode-237 Delete Node in a Linked List
#237. Delete Node in a Linked List Write a function to delete a node (except the tail) in a singl ...
- [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】237 & 203 - Delete Node in a Linked List & Remove Linked List Elements
237 - Delete Node in a Linked List Write a function to delete a node (except the tail) in a singly l ...
- 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] 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 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
237. Delete Node in a Linked List Easy Write a function to delete a node (except the tail) in a sing ...
- [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 ...
随机推荐
- 设计的MOS管三极管简单开关电路驱动能力不够1
您需要 登录 才可以下载或查看,没有帐号?注册 x . ?& P' U5 r/ ~& `: B 用AOD409设计的开关电路为什么驱动能力不够,请大家帮忙分析一下原因啊.这个电路作用就 ...
- 你真的了解电子邮件系统的组成和结构吗?(SMTP、POP3、IMAP、MIME……)
文章转自:https://blog.csdn.net/weixin_43914604/article/details/105896201 学习课程:<2019王道考研计算机网络> 学习目的 ...
- oracle物化视图创建及删除
--删除物化表的日志表 DROP MATERIALIZED VIEW LOG ON 表名; --为将要创建物化视图的表添加带主键的日志表 CREATE MATERIALIZED VIEW LOG ON ...
- uvm_subscriber
subscriber是消费,用户的意思 uvm_subscriber主要作为coverage的收集方式之一 uvm_subscriber的代码非常简单,继承于uvm_component,再加上一个an ...
- X264编码测试验证
之前在做一个rtsp直播需求,其中一个方案是要用的x264来对摄像头数据进行实时编码推流,摄像头帧率是25fps,为了验证方案的可行性,先对x264的编码速度进行一个测试研究,再确认是否要采用此方案. ...
- 20191310Lee_yellow缓冲区溢出实验
缓冲区溢出实验 1.什么是缓冲区溢出 缓冲区溢出是指程序试图向缓冲区写入超出预分配固定长度数据的情况.这一漏洞可以被恶意用户利用来改变程序的流控制,甚至执行代码的任意片段.这一漏洞的出现是由于数据 ...
- 【java+selenium3】自动化基础小结+selenium原理揭秘 (十七)
一.自动化实现原理 1.创建驱动对象 (1) 首先加载浏览器安装目录下的exe文件 (2) 其次是加载可执行驱动的exe文件,监听等待客户端发送的web service请求. 底层原理如下: 1. ...
- 【Django】Mac 安装pip3-install-mysqlclient 报错
1.首先在pip3-install-mysqlclient时报错 mysql_config not found 2.逛了一些博客 让安装mysql或者mysql-connector-c 我安装了后者还 ...
- WebSocket实现简易的FTP客户端
WebScoket的简单应用,实现一个简易的FTP,即文件上传下载,可以查看上传人,下载次数,打开多个Web可以多人上传. 说在前面的话 文件传输协议(File Transfer Protocol,F ...
- <C#任务导引教程>练习九
//75,异常情况using System;class Program{ public static void Main() { Console.Write("请输 ...