当前位置:网站首页>LeetCode 237. 删除链表中的节点
LeetCode 237. 删除链表中的节点
2022-08-10 11:09:00 【水菜笔】
原题网址:https://leetcode.cn/problems/delete-node-in-a-linked-list/
有一个链表,删除给定的节点,无法直接访问到头结点;保证删除的不是最后一个节点;
// node是要删除的节点
// 由于是可以保证删除的不是最后一个节点,所以可以和要删除的后一个节点交换值,之后删除后面的那个
public void deleteNode(ListNode node) {
if(node == null || node.next == null) {
return;
}
ListNode next = node.next;
int tmp = node.val;
node.val = next.val;
next.val = tmp;
node.next = next.next;
}
边栏推荐
猜你喜欢

Do self-media monthly income tens of thousands?Several self-media tools that bloggers are using
![[Brave food, not afraid to write the linked list] The problem of the penultimate node of the linked list](/img/87/7ac0307de54f2defe8f72c554745cd.png)
[Brave food, not afraid to write the linked list] The problem of the penultimate node of the linked list

3款不同类型的自媒体免费工具,有效提高创作、运营效率

LeetCode50天刷题计划(Day 18—— 搜索旋转排序数组(8.50-12.00)
今天面了个腾讯拿38K出来的大佬,让我见识到了基础的天花板

蔚来-软件开发工程师一面记录

MLX90640 红外热成像仪测温传感器 手机 APP 软件 RedEye 连接详细

Since the media hot style title how to write?Taught you how to write the title

振弦传感器及核心VM系列振弦采集模块

学长告诉我,大厂MySQL都是通过SSH连接的
随机推荐
不止跑路,拯救误操作rm -rf /*的小伙儿
[Go WebSocket] 多房间的聊天室(一)思考篇
LeetCode50天刷题计划(Day 17—— 下一个序列(14.50-16.30)
第二十二章 源代码文件 REST API 参考(四)
单目操作符(含原码反码补码转换)
VSCode远程连接服务器报错:Could not establish connection to “xxxxxx”的可能错误原因及解决
网络基础(第一节)
The brave rice rice, does not fear the brush list of 】 list has a ring
WeChat applet, global variables change in one place and the state in other places also changes.
老板加薪!看我做的WPF Loading!!!
关于振弦采集模块及采集仪振弦频率值准确率的问题
LeetCode_628_三个数的最大乘积
flask-restplus接口地址404问题
POJ 2891 Strange Way to Express Integers (Extended Euclidean)
Intel pushes 20220809 CPU microcode update to patch Intel-SA-00657 security vulnerability
振弦传感器及核心VM系列振弦采集模块
建校仅11年就入选“双一流” ,这所高校是凭什么做到的?
CPU多级缓存与缓存一致性
LAXCUS分布式操作系统安全管理
Flutter气泡框实现