当前位置:网站首页>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;
}
};
边栏推荐
- Prefix and array series
- WPF之MVVM
- Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
- 树莓派串口登录与SSH登录方法
- Brief introduction to the curriculum differences of colleges and universities at different levels of machine human major -ros1/ros2-
- Misc of BUU (update from time to time)
- kubernetes集群搭建Zabbix监控平台
- Babbitt | metauniverse daily must read: the group image of Chinese Internet enterprises pouring into metauniverse: "there are only various survival desires, and there is no ambition for forward-lookin
- “无聊猿” BAYC 的内忧与外患
- Interface automation test framework: pytest+allure+excel
猜你喜欢

NFT on fingertips | evaluate ambire on G2, and have the opportunity to obtain limited edition collections

呆错图床系统源码图片CDN加速与破解防盗链功能

The author is dead? AI is conquering mankind with art

Practical guidance for interface automation testing (Part I): what preparations should be made for interface automation

leetcode1020. 飞地的数量(中等)

同事上了个厕所,我帮产品妹子轻松完成BI数据产品顺便得到奶茶奖励

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

Blue Bridge Cup zero Foundation National Championship - day 20

顶测分享:想转行,这些问题一定要考虑清楚!

Wechat brain competition answer applet_ Support the flow main belt with the latest question bank file
随机推荐
UniPro甘特图“初体验”:关注细节背后的多场景探索
首发织梦百度推送插件全自动收录优化seo收录模块
基于PyTorch和Fast RCNN快速实现目标识别
Apache dolphin scheduler source code analysis (super detailed)
Thought map of data warehouse construction
前缀和数组系列
Call, apply, bind rewrite, easy to understand with comments
Arduino tutorial - Simon games
19.段页结合的实际内存管理
BUU的MISC(不定时更新)
Babbitt | metauniverse daily must read: the group image of Chinese Internet enterprises pouring into metauniverse: "there are only various survival desires, and there is no ambition for forward-lookin
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
UNIPRO Gantt chart "first experience": multi scene exploration behind attention to details
Every API has its foundation when a building rises from the ground
微信脑力比拼答题小程序_支持流量主带最新题库文件
作者已死?AI正用艺术征服人类
呆错图床系统源码图片CDN加速与破解防盗链功能
Database basics exercise part 2
Idea console color log
这个高颜值的开源第三方网易云音乐播放器你值得拥有