要求

  • 给定链表中的一个节点,删除该节点

思路

  • 通过改变节点的值实现

 实现

 1 struct ListNode {
2 int val;
3 ListNode *next;
4 ListNode(int x) : val(x), next(NULL) {}
5 };
6
7 class Solution {
8 public:
9 void deleteNode(ListNode* node) {
10
11 if( node == NULL )
12 return;
13
14 if( node->next == NULL){
15 delete node;
16 node = NULL;
17 return;
18 }
19
20 node->val = node->next->val;
21 ListNode* delNode = node->next;
22 node->next = delNode->next;
23
24 delete delNode;
25
26 return;
27 }
28 };

[刷题] 237 Delete Nodes in a Linked List的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 【LeetCode】237. Delete Node in a Linked List 解题报告 (Java&Python&C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 设置当前节点的值为下一个 日期 [LeetCode] ...

  5. [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 ...

  6. 【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 ...

  7. 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 ...

  8. [LeetCode&Python] Problem 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 ...

  9. [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 ...

随机推荐

  1. 分享一次排查CLOSE_WAIT过多的经验

    关键词:TCP.CLOSE_WAIT 问题背景 某日下午有测试人员急匆匆的跑来跟我反馈:"有客户反馈供应商附件预览不了,流程阻塞,需要紧急处理",我立马精神起来,毕竟都是付费客户( ...

  2. 深入学习spring cloud gateway 限流熔断

    前言 Spring Cloud Gateway 目前,Spring Cloud Gateway是仅次于Spring Cloud Netflix的第二个最受欢迎的Spring Cloud项目(就GitH ...

  3. 自动化kolla-ansible部署ubuntu20.04+openstack-victoria之物理机配置-01

    自动化kolla-ansible部署ubuntu20.04+openstack-victoria之物理机配置-01  欢迎加QQ群:1026880196  进行交流学习 近期我发现网上有人转载或者复制 ...

  4. Day07_33_链表

    链表 单链表 双向链表 * 什么是双向链表? 双向链表是链表的一种,由节点组成,每个数据结点中都有两个指针,分别指向直接后继和直接前驱. ![](https://img2020.cnblogs.com ...

  5. JMeter 结果处理常见问题

    1. 前言 2. 结果处理常见问题 1)在察看结果树中只看失败情况 2)如何把日志放入文件查看 3)cvs 文件中文读取乱码 4)失败请求数据的采集 5)结果树响应数据中文乱码解决办法 1. 前言 工 ...

  6. 2.1.1- css产生的原因

    CSS的发展历程 从HTML被发明开始,样式就以各种形式存在.不同的浏览器结合它们各自的样式语言为用户提供页面效果的控制.最初的HTML只包含很少的显示属性.随着HTML的成长,为了满足页面设计者的要 ...

  7. 1.4.19- HTML标签之注释标签

    有的时候我们输入的代码,让你别人看,别人不知道你的思路,可能就看不懂,或者或一段时间自己就看不懂了,这个时候我们需要对代码进行注释,解释我们的代码什么意思: <!DOCTYPE html> ...

  8. Sublime Text 3 Build 3176 License

    先在hosts文件里加入两行: 127.0.0.1 www.sublimetext.com 127.0.0.1 license.sublimehq.com 目的是防止Sublime Text更新和检测 ...

  9. featureCarousel.js 3d轮播图插件

    jQuery Feature Carousel 插件是国外的一比较优秀的旋转木马图片插件. 点击这里进入原文. 插件特点: 1.处理div的3d旋转木马效果. 2.支持一个中心,2个侧面的功能 3.中 ...

  10. 【Springboot】Springboot自动装配原理

    1.核心注解就是 EnableAutoConfiguration  该注解会激活SpringBoot的自动装配功能: 代码如下: @Target(ElementType.TYPE) @Retentio ...