当前位置:网站首页>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;
}
};
边栏推荐
- Pallet management in SAP SD delivery process
- The psychological process from autojs to ice fox intelligent assistance
- Cookie技术&Session技术&ServletContext对象
- A brief introduction of reverseme in misc in the world of attack and defense
- Short video, more and more boring?
- idea控制台彩色日志
- [server data recovery] case of offline data recovery of two hard disks of IBM server RAID5
- Bitcoinwin (BCW): the lending platform Celsius conceals losses of 35000 eth or insolvency
- Zhongqing reading news
- Huawei equipment configuration ospf-bgp linkage
猜你喜欢
Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
【每日一题】729. 我的日程安排表 I
作者已死?AI正用艺术征服人类
Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes
Top test sharing: if you want to change careers, you must consider these issues clearly!
Apache dolphin scheduler source code analysis (super detailed)
Development of entity developer database application
When my colleague went to the bathroom, I helped my product sister easily complete the BI data product and got a milk tea reward
Prefix and array series
Win10 64 bit Mitsubishi PLC software appears oleaut32 DLL access denied
随机推荐
UWA pipeline version 2.2.1 update instructions
3. Business and load balancing of high architecture
Hydra common commands
雲上有AI,讓地球科學研究更省力
作者已死?AI正用艺术征服人类
MPLS experiment
Fast target recognition based on pytorch and fast RCNN
C语言_双创建、前插,尾插,遍历,删除
【Hot100】739. 每日溫度
【服务器数据恢复】IBM服务器raid5两块硬盘离线数据恢复案例
Due to high network costs, arbitrum Odyssey activities are suspended, and nitro release is imminent
26岁从财务转行软件测试,4年沉淀我已经是25k的测开工程师...
Briefly describe the differences between indexes, primary keys, unique indexes, and joint indexes in mysql, and how they affect the performance of the database (in terms of reading and writing)
Arduino tutorial - Simon games
配置树莓派接入网络
C language_ Double create, pre insert, post insert, traverse, delete
微信脑力比拼答题小程序_支持流量主带最新题库文件
LeetCode Algorithm 2181. 合并零之间的节点
RichView TRVStyle 模板样式的设置与使用
呆错图床系统源码图片CDN加速与破解防盗链功能