代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
var addTwoNumbers = function (l1, l2) {
function ListNode(val) {
this.val = val;
this.next = null;
}
function Llist() {
this.head = new ListNode("head");
this.find = find;
this.insert = insert;
}
function find(node) {
var targetNode = this.head;
while (1) {
if (targetNode.val === node) {
break;
}
targetNode = targetNode.next;
}
return targetNode;
}
function insert(newElement, node) {
var newNode = new ListNode(newElement);
var current = this.find(node);
newNode.next = current.next;
current.next = newNode;
}
var op;
if (l1.length < l2.length) {
op = l1;
l1 = l2;
l2 = op;
}
var l1List = new Llist();
var l2List = new Llist();
l1List.insert(l1[0], "head");
l2List.insert(l2[0], "head");
for (var i = 1; i < l1.length; i++) {
l1List.insert(l1[i], l1[i - 1]);
}
for (var i = 1; i < l2.length; i++) {
l2List.insert(l2[i], l2[i - 1]);
}
if (l1.length >= l2.length) {
var flag = 0;
var ppp = [];
var _o1 = l1List.head.next;
var _o2 = l2List.head.next;
var iIndex = 0;
var iIndex1 = 0;
while (_o1 != null) {
ppp[iIndex] = _o1.val;
iIndex++;
_o1 = _o1.next;
}
_o1 = l1List.head.next;
while (1) {
if (_o1 == null || _o2 == null) {
alert(ppp);
// return ppp;
break;
} else {
if (_o1.val + _o2.val >= 10) {
if (flag) {
ppp[iIndex1] = (_o1.val + _o2.val) % 10 + 1;
} else {
ppp[iIndex1] = (_o1.val + _o2.val) % 10;
}
flag = 1;
iIndex1++;
_o1 = _o1.next;
_o2 = _o2.next;
} else {
if (flag) {
ppp[iIndex1] = _o1.val + _o2.val + 1;
} else {
ppp[iIndex1] = _o1.val + _o2.val;
}
flag = 0;
iIndex1++;
_o1 = _o1.next;
_o2 = _o2.next;
}
}
}
}
};
addTwoNumbers([2,4,3], [5,6,4]);
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。