当前位置:网站首页>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;
}
};
边栏推荐
- win10 64位装三菱PLC软件出现oleaut32.dll拒绝访问
- Kubernetes cluster builds ZABBIX monitoring platform
- Bitcoinwin (BCW): the lending platform Celsius conceals losses of 35000 eth or insolvency
- Oracle database 11gr2 uses TDE transparent data encryption to report an error ora28353. If you run to close the wallet, you will report an error ora28365. If you run to open the wallet, you will repor
- 19.段页结合的实际内存管理
- [hot100] 739. Température quotidienne
- Arduino tutorial - Simon games
- AI on the cloud makes earth science research easier
- MPLS experiment
- Depth residual network
猜你喜欢
Establishment and operation of cloud platform open source project environment
Hydra common commands
leetcode841. Keys and rooms (medium)
“无聊猿” BAYC 的内忧与外患
指尖上的 NFT|在 G2 上评价 Ambire,有机会获得限量版收藏品
What is the difference between int (1) and int (10)? Senior developers can't tell!
AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/home/yolov5/models/comm
Practical guidance for interface automation testing (Part I): what preparations should be made for interface automation
升级版手机检测微信工具小程序源码-支持多种流量主模式
AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/home/yolov5/models/comm
随机推荐
leetcode1020. 飞地的数量(中等)
Raspberry pie serial port login and SSH login methods
巴比特 | 元宇宙每日必读:中国互联网企业涌入元宇宙的群像:“只有各种求生欲,没有前瞻创新的雄心”...
Latex文字加颜色的三种办法
L'Ia dans les nuages rend la recherche géoscientifique plus facile
BIO模型实现多人聊天
Missing monitoring: ZABBIX monitors the status of Eureka instance
UNIPRO Gantt chart "first experience": multi scene exploration behind attention to details
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
19. Actual memory management of segment page combination
leetcode35. 搜索插入位置(简单,找插入位置,不同写法)
Attributeerror: can 't get attribute' sppf 'on < module' models. Common 'from' / home / yolov5 / Models / comm
Leetcode35. search the insertion position (simple, find the insertion position, different writing methods)
ROS学习_基础
WPF之MVVM
编译,连接 -- 笔记 -2
雲上有AI,讓地球科學研究更省力
《从0到1:CTFer成长之路》书籍配套题目(周更)
Due to high network costs, arbitrum Odyssey activities are suspended, and nitro release is imminent
leetcode6109. 知道秘密的人数(中等,周赛)