代码拉取完成,页面将自动刷新
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;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。