LeetCode 2. Add Two Numbers -- 两个链表按序从头到尾相加,记录进位

该博客介绍了如何解决LeetCode上的2题——将两个按逆序存储的非负整数链表相加。文章讨论了两种方法,其中方法1是正确的解决方案,能够有效处理链表并记录进位,而方法2则被指出是错误的。正确方法的运行效率超过了87.48%的Java提交。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

Input: (1 -> 4 -> 3) + (5 -> 8 -> 4)
Output: 6 -> 2 -> 8

Constraints:

  • The number of nodes in each linked list is in the range [1, 100].//100位数,int/long会溢出
  • 0 <= Node.val <= 9
  • It is guaranteed that the list represents a number that
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

二十六画生的博客

你的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值