当前位置:网站首页>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;
}
};
边栏推荐
- Visitor tweets about how you can layout the metauniverse
- Thought map of data warehouse construction
- [advanced software testing step 1] basic knowledge of automated testing
- TS Basics
- BUU的MISC(不定时更新)
- A method to measure the similarity of time series: from Euclidean distance to DTW and its variants
- Short video, more and more boring?
- Bitcoinwin (BCW): 借贷平台Celsius隐瞒亏损3.5万枚ETH 或资不抵债
- AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models. common‘ from ‘/home/yolov5/models/comm
- ROS2安装及基础知识介绍
猜你喜欢

前缀和数组系列

UWA pipeline version 2.2.1 update instructions

Configure raspberry pie access network

Internal and external troubles of "boring ape" bayc

Visitor tweets about how you can layout the metauniverse

A method to measure the similarity of time series: from Euclidean distance to DTW and its variants

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

ROS2安装及基础知识介绍

After working for 10 years, I changed to a programmer. Now I'm 35 + years old and I'm not anxious

Raspberry pie serial port login and SSH login methods
随机推荐
Every API has its foundation when a building rises from the ground
GET 和 POST 请求类型的区别
Internal and external troubles of "boring ape" bayc
Simple use of MySQL database: add, delete, modify and query
这个高颜值的开源第三方网易云音乐播放器你值得拥有
UniPro甘特图“初体验”:关注细节背后的多场景探索
首发织梦百度推送插件全自动收录优化seo收录模块
Brief introduction to the curriculum differences of colleges and universities at different levels of machine human major -ros1/ros2-
L'Ia dans les nuages rend la recherche géoscientifique plus facile
Three methods of adding color to latex text
TS Basics
Zhongqing reading news
接口自动化测试框架:Pytest+Allure+Excel
C language_ Double create, pre insert, post insert, traverse, delete
Cif10 actual combat (resnet18)
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
Fedora/rehl installation semanage
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
leetcode6109. 知道秘密的人数(中等,周赛)
作者已死?AI正用藝術征服人類