当前位置:网站首页>leetcode445. 两数相加 II
leetcode445. 两数相加 II
2022-07-16 03:57:00 【henujolly】
class Solution {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
Deque<Integer>q1=new ArrayDeque<>();
Deque<Integer>q2=new ArrayDeque<>();
while(l1!=null){
q1.push(l1.val);
l1=l1.next;
}
while(l2!=null){
q2.push(l2.val);
l2=l2.next;
}
int carry=0;
ListNode ans=null;
while(!q1.isEmpty()||!q2.isEmpty()|| carry != 0){
int n1=q1.isEmpty()?0:q1.poll();
int n2=q2.isEmpty()?0:q2.poll();
int sum=n1+n2+carry;
carry=sum/10;
ListNode cur=new ListNode(sum%10);
cur.next=ans;
ans=cur;
}
return ans;
}
}
边栏推荐
- Sword finger offer 10- I. Fibonacci sequence
- Low power test scheme of jishili multimeter
- Global location number Gln application introduction
- Brush questions in summer vacation
- [software testing] test slang, the advice given to you by ten-year old employees
- [TinyML]NetAug:Network Augmentation for Tiny Deep Learning
- 晴空一“鹤”排“云”上:以数为翅的中国飞鹤
- How can the computer recover deleted files? How can I recover deleted data
- 312312dd
- Time consuming evaluation of image pixel values accessed by opencv, emgucv and opencvsharp pointers (with source code)
猜你喜欢

软件测试月薪28K大厂面试题 (经面试官允许可以拿走试卷)

After Jay Chou's co branded model, Fang Wenshan brought online shopping to promote the collection of "Hualiu" top-level co branded dolls

DPR-34、AC220V双位置继电器

2.18 haas506 2.0开发教程 - 阿里云M2M设备间通信 - 规则引擎/Topic消息路由(仅支持2.2以上版本)

Introduction of oscilloscope bandwidth

Tools to measure the gap between two distributions: cross entropy and KL divergence

五、jmeter脚本的基本构成&断言

OpenCvSharp (C# OpenCV) 指针方法读取和修改图像像素值(附源码)

Sword finger offer 26 Substructure of tree
![[machine learning] decision tree](/img/ae/7dac0bddc7f55ecabe49ab5ef4b429.png)
[machine learning] decision tree
随机推荐
Find the number of daffodils
探索式软件测试
Use PSSH to execute commands on multiple hosts in batches
[software testing] test slang, the advice given to you by ten-year old employees
Template_ Euclidean sieve_ prime number
[RT thread] NXP rt10xx sfud and fal component construction and use
DLS-42/4-4 DC110V双位置继电器
ACL技术
DLS-12B/DC220V双位置继电器
双位置继电器DLS-5/1
DPR-34、AC220V双位置继电器
蓝牙技术|首批蓝牙LE Audio兼容设备年内上市,蓝牙耳机续航将突飞猛进
More than 130 enterprises and 3500 developers have jointly built the root community of opengauss open source database
Common protocols of tcp/ip
Static routing technology
How to generate non repeated random numbers in Excel, multi method + principle
Sword finger offer 10- ii Frog jumping on steps
Sword finger offer 18 Delete the node of the linked list
How to choose a desktop multimeter?
MulterError: Unexpected field