当前位置:网站首页>2. 两数相加
2. 两数相加
2022-07-26 14:37:00 【superkcl2022】


1.常规链表
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()
}
}
边栏推荐
- SiamRPN:建议区域网络与孪生网络
- [Nuxt 3] (十二) 项目目录结构 1
- SA Siam: Twin network for real-time target tracking
- 次轮Okaleido Tiger即将登录Binance NFT,引发社区热议
- 过滤器和拦截器的区别
- 自编码器 AE(AutoEncoder)程序
- Canvas laser JS special effect code
- Instructions for various interfaces of hand-held vibrating wire collector vh03
- 【1.2.投资的收益和风险】
- 基于CAS的SSO单点客户端配置
猜你喜欢

4 kinds of round head arrangement styles overlay styles

Use of LINGO software

Some lightweight network models in detection and segmentation (share your own learning notes)

【方差分析】之matlab求解

SiamRPN:建议区域网络与孪生网络

Win11运行虚拟机死机了?Win11运行VMware虚拟机崩溃的解决方法

VBA 上传图片

Wechat applet - "do you really understand the use of applet components?

RPN:Region Proposal Networks (区域候选网络)

Minecraft 1.16.5模组开发(五十二) 修改原版生物战利品 (Loot Table)
随机推荐
sqlDeveloper工具快速入门
14. Bridge based active domain adaptation for aspect term extraction reading notes
Brief description of llcc68 broadcast wake-up
c# 用移位 >> 和运算与 &判断两个 二进制数 是否发生过改变
Seata的部署与微服务集成
go开发调试之Delve的使用
C common function integration
C # use shift > > and operation and & to judge whether the two binary numbers have changed
图神经网络Core数据集介绍
winscp传输文件和VNC连接问题
Use of delve for go development and debugging
The development of smart home industry pays close attention to edge computing and applet container technology
Canvas laser JS special effect code
PyTorch的简单实现
当AI邂逅生命健康,华为云为他们搭建三座桥
leetcode汇总
Parsing XML files using Dom4j
maya将模型导入到unity
C语言入门必刷100题合集之每日一题(1-20)
The difference between torch.nn and torch.nn.functional in pytorch