要求

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

思路

  • 通过改变节点的值实现

 实现

 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. 运维趋势2019年总结,运维就是要做到"技多不压身"

    2019年 在互联网这个行业中对运维的要求越来越来越高,比如2015.16年的时候,运维只是做一些人力投入的事情,比如重启个服务,搭建一个nginx,mysql主从服务,简单的优化一下,就可以上线了, ...

  2. 敏捷史话(十三):我被 Facebook 解雇了——Kent Beck

    2011年,Kent Beck 加入了 Facebook .那时候的他已年过半百,几十年的经验让他自认为非常了解软件行业.在 Facebook 的新手训练营期间,Kent 开始意识到,Facebook ...

  3. day-03-基础数据类型

    基础数类型总览 10203 123 3340 int +- * / 等等 '今天吃了没?' str 存储少量的数据,+ *int 切片, 其他操作方法 True False bool 判断真假 [12 ...

  4. JS基础学习第六天

    数组(Array) 数组也是一个对象,它和普通的对象一样,也是用来存储一些值的,不同的是普通对象是使用字符串作为属性名的,而数组使用数字作为索引来操作元素数组的存储性能比普通对象好,再开发中我们经常使 ...

  5. 聊聊 OAuth 2.0 的 Token 续期处理

    Token 校验逻辑 // CheckTokenEndpoint.checkToken @RequestMapping(value = "/oauth/check_token") ...

  6. JDK8之后,在java语言这条路怎么走?

    前言 自2017年9月以来,Oracle按照免费的开源许可证(类似于Linux的许可证)提供JDK版本 .从Java SE 11(2018年9月,LTS)开始,Oracle不仅为开源许可下的所有用户免 ...

  7. editorconfig、eslint、prettier三者的区别、介绍及使用

    每次搭建新项目都少不了这些工具,但时间一久就忘记了,下次搭新项目时又要四处查官方文档,因此特此记录,主要内容是对这三个工具的理解,以及具体使用方式 editorconfig 理解 先看官网的定义: E ...

  8. Molar mass UVA - 1586

    ​ An organic compound is any member of a large class of chemical compounds whose molecules contain c ...

  9. 鸿蒙手机版JNI实战(JNI开发、SO库生成、SO库使用)

    鸿蒙JNI开发现状 现阶段,不仅鸿蒙JNI相关的开发资料较少,而且Phone相关的JNI开发资料几乎没有,这对于新入行的鸿蒙开发者们来说,非常不友好. 也可能会给Android工程(使用了SO库的工程 ...

  10. Vue.js小案例、生命周期函数及axios的使用

    一.调色框小案例: 随着三个滑动框的变化,颜色框的颜色随之改变 1.1.实例代码 <!DOCTYPE html> <html lang="en" xmlns:v- ...