当前位置:网站首页>2. Add two numbers
2. Add two numbers
2022-07-26 14:53:00 【superkcl2022】


1. Regular linked list
class ListNode {
int val;
ListNode next;
ListNode() {
}
ListNode(int val) {
this.val = val; }
ListNode(int val, ListNode next) {
this.val = val; this.next = next; }
}
public class Solution {
// 2->4->3
// 5->6->4
// 7->0->8
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
ListNode head,tail;
head = tail = new ListNode(-1);
int jw = 0;
while(l1 != null || l2 != null || jw != 0){
tail.next = new ListNode(jw);
tail = tail.next;
if(l1 != null){
tail.val += l1.val;
l1 = l1.next;
}
if(l2 != null){
tail.val += l2.val;
l2 = l2.next;
}
jw = tail.val / 10;
tail.val %= 10;
}
return head.next;
}
public static void main(String[] args) {
Solution solution = new Solution();
//solution.addTwoNumbers()
}
}
边栏推荐
- JS to realize the number to amount price thousand separator
- WPF 常用功能整合
- WPF common function integration
- Classic line style login interface
- Embedded development: skills of debugging embedded software
- Canvas mesh wave animation JS special effect
- 31. Opinion based relational pivoting forcross domain aspect term extraction reading notes
- Unity learning notes – infinite map
- JS creative range select drag and drop plug-ins
- Maya imports the model into unity
猜你喜欢

自编码器 AE(AutoEncoder)程序
Network pictures are transferred locally, causing the kernel to exit

C# NanUI 相关功能整合

TransC知识表示模型

14. Bridge-Based Active Domain Adaptation for Aspect Term Extraction 阅读笔记

1. Sum of two numbers

基于CAS的SSO单点登录环境搭建
![[Yugong series] July 2022 go teaching course 017 - if of branch structure](/img/e4/b3aa4b8bda738aadded3127a8b3485.png)
[Yugong series] July 2022 go teaching course 017 - if of branch structure

Flask send_ Absolute path traversal caused by file function

NLP之NER:商品标题属性识别探索与实践
随机推荐
保证接口数据安全的10种方案
The development of smart home industry pays close attention to edge computing and applet container technology
【1.2.投资的收益和风险】
下一代视觉Transformer:解锁CNN和Transformer正确结合方法
C winfrom common function integration
网络图片转本地导致内核退出
Seata deployment and microservice integration
Whaledi message queue stability improvement practice
Siamfc: full convolution twin network for target tracking
【文件上传漏洞-06】分布式配置文件攻击实验—以upload-labs-4为例
Would you please tell me if there is a way for Flink SQL not to output update_ before?
JS wave animation effect menu style
SA-Siam:用于实时目标跟踪的孪生网络
堆叠降噪自动编码器 Stacked Denoising Auto Encoder(SDAE)
WPF common function integration
14. Bridge-Based Active Domain Adaptation for Aspect Term Extraction 阅读笔记
1. Sum of two numbers
VP video structured framework
llcc68广播唤醒简单说明
As the "first city" in Central China, Changsha's "talent attraction" has changed from competition to leadership