当前位置:网站首页>模拟加法 & 结构体基本用法
模拟加法 & 结构体基本用法
2022-07-24 05:15:00 【rejudge】
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next) {} * }; */
class Solution {
public:
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
struct ListNode* dummy=new ListNode(-1);
struct ListNode* cur=dummy;
//或者
auto dummy=new ListNode(-1),cur=dummy;
int t=0;
while(l1 || l2 || t)
{
if(l1) t+=l1->val,l1=l1->next;
if(l2) t+=l2->val,l2=l2->next;
cur->next=new ListNode(t%10);
cur=cur->next;
t/=10;
}
return dummy->next;
}
};
边栏推荐
- Blue Bridge Cup 31 day sprint 21 day (C language)
- Heavy! The 2022 China open source development blue book was officially released
- 1、基于增量式生成遮挡与对抗抑制的行人再识别
- Optional consistency
- PPPoE网关模拟环境搭建
- 酒店IPTV数字电视系统解决方案
- NumPy 统计相关函数示例教程
- Binary SCA fingerprint extraction black Technology: go language Reverse Technology
- Career planning route
- JDBC MySQL basic operations
猜你喜欢

Update C language notes
![[database connection] - excerpt from training](/img/7d/334b4b7f0f6e1de228c4ecb1e600a3.png)
[database connection] - excerpt from training

JMeter FAQs

Chapter5 foundation of deep learning

明星逆市入局的NFT,如何能走出独立行情?

On the dilemma faced by non transferable reputation points NFT SBTS

SSH service

The fourth job: about the usage of cat, grep, cut, sort, uniq, VIM, TR and other commands

Token of space renewable energy

利用a*启发式搜索解决迷宫寻路问题
随机推荐
Image painting for irregular holes using partial revolutions paper notes
SSM整合
[basic 7] - exceptions, capture and customize exceptions
DNS domain name resolution service
Support complex T4 file systems such as model group monitoring and real-time alarm. e
Illustration and text demonstrate the movable range of the applet movable view
NFS shared services
Teach you how to weld CAD design board bottom (for beginners) graphic tutorial
How can NFT, whose stars enter the market against the market, get out of the independent market?
线程的介绍
Ia notes 2
DHCP principle and configuration
[database connection] - excerpt from training
)To feed back to the application layer or into multiple format documents:
Data annotation learning summary
In his early 30s, he became a doctoral director of Fudan University. Chen Siming: I want to write both codes and poems
线程
一文带你深入浅出C字符串函数和内存函数
Read "effective managers - Drucker"
Source code compilation!!