当前位置:网站首页>LeetCode Algorithm 2181. Merge nodes between zero
LeetCode Algorithm 2181. Merge nodes between zero
2022-07-06 07:06:00 【Alex_ 12 hours a day 6 days a week】
Topic link :2181. Merge nodes between zeros
Ideas
Algorithm : iteration
data structure : Linked list
Ideas : In fact, you can create a new linked list res, And then through head Traverse the original list , encounter 0 Create a new node and mount it to res Tail of , Until we meet the next one 0 node , Otherwise, just let res The tail node value of plus the node currently being traversed .
Code
C++
class Solution {
public:
ListNode* mergeNodes(ListNode* head) {
ListNode *dummyHead = new ListNode(0);
ListNode *cur = dummyHead;
while (head->next != nullptr) {
if (head->val == 0) {
ListNode *node = new ListNode(0);
cur->next = node;
cur = node;
}
cur->val += head->val;
head = head->next;
}
return dummyHead->next;
}
};
边栏推荐
- AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/home/yolov5/models/comm
- Huawei equipment configuration ospf-bgp linkage
- 【Hot100】739. Daily temperature
- Prefix and array series
- What is the biggest problem that fresh e-commerce is difficult to do now
- Map of mL: Based on the adult census income two classification prediction data set (whether the predicted annual income exceeds 50K), use the map value to realize the interpretable case of xgboost mod
- 18.多级页表与快表
- 3. Business and load balancing of high architecture
- Development of entity developer database application
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
猜你喜欢

因高额网络费用,Arbitrum 奥德赛活动暂停,Nitro 发行迫在眉睫

首发织梦百度推送插件全自动收录优化seo收录模块

树莓派3B更新vim

Cookie技术&Session技术&ServletContext对象

leetcode704. 二分查找(查找某个元素,简单,不同写法)

Hydra common commands

win10 64位装三菱PLC软件出现oleaut32.dll拒绝访问

Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案

Brief introduction to the curriculum differences of colleges and universities at different levels of machine human major -ros1/ros2-

CDN acceleration and cracking anti-theft chain function
随机推荐
AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/home/yolov5/models/comm
巴比特 | 元宇宙每日必读:中国互联网企业涌入元宇宙的群像:“只有各种求生欲,没有前瞻创新的雄心”...
呆错图床系统源码图片CDN加速与破解防盗链功能
PCL实现选框裁剪点云
C language_ Double create, pre insert, post insert, traverse, delete
Raspberry pie serial port login and SSH login methods
Refer to how customer push e-commerce does content operation
Proteus -- Serial Communication parity flag mode
【服务器数据恢复】IBM服务器raid5两块硬盘离线数据恢复案例
《从0到1:CTFer成长之路》书籍配套题目(周更)
Blue Bridge Cup zero Foundation National Championship - day 20
LeetCode 78:子集
ROS学习_基础
编译,连接 -- 笔记 -2
Raspberry pie 3B update VIM
Reflex WMS medium level series 3: display shipped replaceable groups
Pymongo gets a list of data
18.多级页表与快表
leetcode1020. 飞地的数量(中等)
[advanced software testing step 1] basic knowledge of automated testing