当前位置:网站首页>模拟加法 & 结构体基本用法
模拟加法 & 结构体基本用法
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;
}
};
边栏推荐
猜你喜欢

Introduction to 51 single chip microcomputer (dedicated to the most understandable article for beginners)

Teach you how to weld CAD design board bottom (for beginners) graphic tutorial

Beginners' preparation for the Blue Bridge Cup (University Programming learning history records, topic ideas for students who need to prepare for the Blue Bridge Cup)

Basic knowledge of MySQL database

PostgreSQL: run PostgreSQL + pgadmin 4 in docker

Tips for using BeanShell built-in variable prev

Tips for using the built-in variable vars in BeanShell

Zhaoyi innovation gd25wdxxk6 SPI nor flash product series comes out

反射的介绍

The difference between run and start in thread class
随机推荐
The opening ceremony of the 2022 Huawei developer competition in China kicked off!
泛型和注解
Pointer learning diary (I)
JDBC MySQL basic operations
MySQL连接
finally和return的执行顺序
PPPoE gateway simulation environment setup
[deep learning] (III) image classification
How to avoid the most common mistakes when building a knowledge base?
Embedded system transplantation [2] - Construction of cross development environment
What are the core strengths of a knowledge base that supports customers quickly?
Wang Qing, director of cloud infrastructure software research and development of Intel (China): Intel's technology development and prospects in cloud native
Hotel IPTV digital TV system solution
酒店IPTV数字电视系统解决方案
ssm的整合
Do you want to have a robot that can make cartoon avatars in three steps?
Scikit learn -- steps of machine learning application development
1、基于增量式生成遮挡与对抗抑制的行人再识别
DNS domain name resolution service
FTP file transfer protocol