要求

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

思路

  • 通过改变节点的值实现

 实现

 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. 分享15个实用VSCode插件,快来收藏吧!

    Visual Studio Code 是由微软开发的一款免费.跨平台的文本编辑器.它有卓越的性能和丰富的功能.VSCode 也有一个扩展和主题市场,为了帮助大家挑选出值得下载的插件,我们针对性的收集了 ...

  2. day-06-集合-缓存机制-深浅copy

    (1) is id ==用法 is 判断的是内存地址是否相同 id 查看内存地址:id相同,值一定相同,值相同,id不一定相同 == 比较判断是否相等 l1 = [1, 2, 3] l2 = [1, ...

  3. java面试-CountDownLatch、CyclicBarrier、Semaphore谈谈你的理解

    一.CountDownLatch 主要用来解决一个线程等待多个线程的场景,计数器不能循环利用 public class CountDownLatchDemo { public static void ...

  4. 安装Dynamics CRM Report出错处理一

    删除下面两个注册表项 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce.HKEY_CURRENT_USER\So ...

  5. 解决Docker MySQL无法被宿主机访问的问题

    1 问题描述 Docker启动MySQL容器后,创建一个localhost访问的用户: create user test@localhost identified by 'test'; 但是在宿主机中 ...

  6. Team Queue UVA - 540

      Queues and Priority Queues are data structures which are known to most computer scientists. The Te ...

  7. 计算机网络第一章bb测试

    错题8,31 课程 211计算机网络 测试 网络概论与体系结构 状态 已完成 尝试分数 得 340 分,满分 360 分 已用时间 14 分钟 说明 第一章 网络概论测试 显示的结果 所有答案, 已提 ...

  8. Scrum Meeting 目录 && alpha 第一次Scrum Meeting博客

    是兄弟就来摸鱼小组 Scrum Meeting 博客汇总 一.Alpha阶段 标号 标题 1 [alpha]第一次Scrum Meeting(见本文) 二.Beta阶段 会议安排 时间 4月23日8时 ...

  9. MySQL8安装教程及问题解决

    目录 1.下载MySQL的zip文件,解压,在根目录(bin所在的目录)下创建my.ini文件 2.管理员模式打开命令提示符(shell或者说小黑窗),按以下命令操作. 3.不过......我这里密码 ...

  10. 2.1.3- 体会css样式

    css初始 css样式规则 代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta cha ...