当前位置:网站首页>10.1-----19. Delete the Nth node from the bottom of the linked list
10.1-----19. Delete the Nth node from the bottom of the linked list
2022-08-09 02:06:00 【@baigui】
一、题目

二、代码
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next) {} * }; */
class Solution {
public:
ListNode* removeNthFromEnd(ListNode* head, int n) {
///统一链表格式
ListNode* dummyhead = new ListNode(0); //设置虚假的头结点 为了使得单节点和多节点情况统一
dummyhead->next = head;
ListNode* process_node = new ListNode(0);
process_node=dummyhead;
int the_sum_of_the_node=0;
while(head!=nullptr)
{
the_sum_of_the_node+=1;
head=head->next;
}
std::cout<<"the_sum_of_the_node "<< the_sum_of_the_node <<std::endl;
int the_number_of_the_delete=the_sum_of_the_node+1-n;
std::cout<<"the_number_of_the_delete "<< the_number_of_the_delete <<std::endl;
int count_the_number=1;
while(count_the_number<the_number_of_the_delete)
{
count_the_number=count_the_number+1;
process_node=process_node->next;
}
//跳出时,process_nodeShould point exactly to the one before the node that needs to be deleted
process_node->next=process_node->next->next;
return dummyhead->next;
}
};
三、运行结果

边栏推荐
- 面试秘籍 | 软件测试必备的mysql数据库技术
- Go-11-流程控制
- LeetCode每日两题01:有序数组的平方 (均1200道)方法:双指针
- 线段树知识整理
- ROS2 ERROR: OpenGL 1.5 is not supported in GLRenderSystem::initialiseContext at C:\ci\ws\build...
- PMP有什么答题技巧?
- 全文翻译:欧盟第29条数据保护工作组 数据保护官指南
- Significance Test--Study Notes
- MT4 / MQL4 entry to the master of EA course lesson two - commonly used functions
- typescript90-使用类型文件声明类型
猜你喜欢

MT4 / MQ4L entry to the master of EA tutorial lesson two (2) - - MQL language commonly used function account information commonly used functions

mysql连接超过八小时报错

Likou Brush Question Record 8.1-----206. Reverse linked list

德语翻译器在线翻译中文

eladmin容器部署超详细过程

How to install ngrok in Synology system (Synology 6.X version)

字节输入流(InputStream)与字节输出流(OutputStream)

力扣刷题记录9.1-----24. 两两交换链表中的节点

Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules

Wireshark packet capture tool
随机推荐
增额终身寿险哪家最好呢?真的安全吗?
Go-8-Gin框架
谷歌翻译下载-免费谷歌翻译软件下载
力扣刷题记录--常用功能函数
Etcd realize large-scale application service management of actual combat
Docker redis master-slave replication setup, the container cannot be started?
全文翻译:EDPB关于VVA(虚拟语音助理)中处理个人数据的指南02/2021
低代码开发创新企业应用构建模式
ROS2 ERROR: OpenGL 1.5 is not supported in GLRenderSystem::initialiseContext at C:\ci\ws\build...
2022/8/8 比赛思维+状压dp
Introduction to LVGL (based on v8.1-8.2)
力扣刷题记录4.1-----209. 长度最小的子数组
typescript91-添加任务基本实现
torchversion.transforms的使用
Electromagnetic radiation safety standards and detection methods
My thoughts on software development
UsernameAuthenticationFilter授权成功后调用AuthenticationSuccessHandler时的解析
Several ways to use JS to achieve array flattening
2020.12.4 log
面试秘籍 | 软件测试必备的mysql数据库技术