1 Star 0 Fork 0

Neo_1001/LeetCode刷题记录

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
LC_2_wrong.java 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
Neo_1001 提交于 2024-04-10 22:16 . first commit
package LeetCode;
public class LC_2_wrong {
public class ListNode {
long val;
ListNode next;
ListNode() {
}
ListNode(long val) {
this.val = val;
}
ListNode(long val, ListNode next) {
this.val = val;
this.next = next;
}
}
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
long num1 = 0;
long num2 = 0;
ListNode p1 = l1;
ListNode p2 = l2;
long idx = 0;
while (p1 != null) {
num1 += p1.val * Math.pow(10, idx);
idx++;
p1 = p1.next;
}
idx = 0;
while (p2 != null) {
num2 += p2.val * Math.pow(10, idx);
idx++;
p2 = p2.next;
}
long resNum = num1 + num2;
if (resNum == 0) {
return new ListNode(0);
}
long tmp = 0;
ListNode res = new ListNode();
ListNode p3 = res;
while (resNum != 0) {
tmp = resNum % 10;
resNum /= 10;
p3.next = new ListNode(tmp);
p3 = p3.next;
}
return res.next;
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/neo1001/leet-code-practice-record.git
git@gitee.com:neo1001/leet-code-practice-record.git
neo1001
leet-code-practice-record
LeetCode刷题记录
master

搜索帮助