题目:

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.

编码:

 1 /**
 2  * Definition for singly-linked list.
 3  * public class ListNode {
 4  *     int val;
 5  *     ListNode next;
 6  *     ListNode(int x) { val = x; }
 7  * }
 8  */
 9 public class Solution {
10     public void deleteNode(ListNode node) {
11         node.val = node.next.val;
12         node.next = node.next.next;
13     }
14 }

转载于:https://www.cnblogs.com/cactus1504/p/4807524.html

leetcode 237: Delete Node in a Linked List相关推荐

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

  2. LeetCode刷题记录3——237. Delete Node in a Linked List(easy)

    LeetCode刷题记录3--237. Delete Node in a Linked List(easy) 目录 LeetCode刷题记录3--237. Delete Node in a Linke ...

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

  4. Leet Code OJ 237. Delete Node in a Linked List [Difficulty: Easy]

    题目: Write a function to delete a node (except the tail) in a singly linked list, given only access t ...

  5. Xiaohe-LeetCode 237 Delete Node in a Linked List

    This is almost the best solution.16ms. /** * Definition for singly-linked list. * struct ListNode { ...

  6. C#LeetCode刷题之#237-删除链表中的节点(Delete Node in a Linked List)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3832 访问. 请编写一个函数,使其可以删除某个链表中给定的(非末 ...

  7. LeetCode 450 Delete Node in a BST(二叉搜索树中的删除结点)

    问题:给出一个二叉搜索树,删除指定的结点,要求返回删除后的树. 算法思路: 1.删除的结点是叶子结点,则直接删除 2.删除的结点只有一个子结点(左孩子右孩子),则直接用子结点替换 3.删除的结点左右孩 ...

  8. java中删除node节点_[Java]LeetCode237. 删除链表中的节点 | Delete Node in a Linked List

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...

  9. Jan 12 - Delete Node in a Linked List; Data Structure; Linked List; Pointer;

    代码: /*** Definition for singly-linked list.* public class ListNode {* int val;* ListNode next;* List ...

最新文章

  1. iOS开发网络——数据缓存
  2. 【每日进步】May 2012
  3. 每天最少编码1000行
  4. cross product
  5. Chapter1-5_Speech_Recognition(Alignment of HMM, CTC and RNN-T)
  6. Python 二维创建与插入值的二种方法
  7. Yii防注入攻击笔记
  8. 蓝桥杯 ALGO-94 算法训练 新生舞会
  9. 使用vs2008搭建php扩展环境
  10. 基于Simulink与FlightGear联合建模并仿真多旋翼无人机在平衡态的动态控制
  11. 记录08_7.15~7.16
  12. 无危害有好玩的电脑病毒下载-01期
  13. 138529-46-1,Biotin-PEG2-amine可在EDC或HATU存在下与NHS酯或羧酸反应试剂
  14. github star整理
  15. 【规范】万字集大成的C编写规范
  16. 电驴提示“该内容尚未提供权利证明,无法提供下载”之解决办法
  17. 力软:九年沉淀,从呱呱坠地到风华少
  18. 谷粒学院项目对应知识点
  19. MD4加密java算法
  20. 【渝粤教育】电大中专建筑材料_1作业 题库

热门文章

  1. php pthread安装编译,php 多线程扩展 pthreads 安装 及 使用
  2. thinkphp5+远程代码执行_ThinkPHP5 5.0.23 远程代码执行漏洞
  3. 用python设计学生管理系统_python+tkinter实现学生管理系统
  4. swift java混合,如何在Swift中连接或合并数组?
  5. asp 设置table 间距_B端后台表格(table)如何设计
  6. 归并排序(代码注释超详细)
  7. 如何在html中选择wrap,使用jQuery中的wrap()函数操作HTML元素的教程
  8. Linux镜像如何添加驱动,安装virtio驱动(Linux)
  9. Linux 文件夹详情,linux使用命令创建文件夹以及里面的文件,详情介绍
  10. Java8 新的 try-with-resources 语句,自动资源释放