博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode237-Delete Node in a Linked List
阅读量:6914 次
发布时间:2019-06-27

本文共 758 字,大约阅读时间需要 2 分钟。

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->3->4->5,我们要删除结点3,可以让3赋值为4,3指向5。那么就变成了1->2->4->5,^_^结果就得到了

/** * Definition for singly-linked list. * struct ListNode { *     int val; *     struct ListNode *next; * }; */void deleteNode(struct ListNode* node) {    if(node==NULL)    {        return ;    }    else    {        node->val=node->next->val;        node->next=node->next->next;    }}

 

转载于:https://www.cnblogs.com/liuyifei/p/Delete_Node_in_a_Linked_List.html

你可能感兴趣的文章
Ehcache(07)——Ehcache对并发的支持
查看>>
关于Eclipse中配置产品启动的插件
查看>>
在循环中创建网页元素的问题
查看>>
ACM零散知识
查看>>
【转】Spring@Autowired注解与自动装配
查看>>
JVM学习笔记(一)------基本结构
查看>>
【Intel AF 2.1 学习笔记三】
查看>>
知名黑客组织Anonymous(匿名者)的装备库
查看>>
Mac OS中Java Servlet与Http通信
查看>>
微软职位内部推荐-Principal Software Eng Mgr
查看>>
MySQL 添加外键约束,不检查现有数据
查看>>
arduino一些内容
查看>>
Entity Framework 基础知识走马观花
查看>>
Ozmosis实现BIOS直接启动Yosemite,基本完美
查看>>
document.createElement()的用法
查看>>
使用 CSS3 实现超炫的 Loading(加载)动画效果
查看>>
Redis基础知识之—— 5个必须了解的事情【★★★★★】
查看>>
C#创建安全的栈(Stack)存储结构
查看>>
Django中的许可(Permissions)和用户组(Group)
查看>>
阿里大鱼发送短信
查看>>