1. LeetCode question one
Requirements: https://leetcode-cn.com/probl… Given an integer array nums and an integer target, find the two integers in the array whose sum is the target value and return their array index. Nums = [2,7,11,15], target = 9
let nums = [2, 7, 11, 15]; Function print(nums, target) {// let hash = {}; for (let i = 0; i < nums.length; I ++) {// Stores the data in each loop if index = 0={2:0} hash[I] = I; If (hash[target-nums [I]]! = hash[I]! = hash[I]! = hash[I]! = hash[I]! = hash[I]! = undefined) {return [hash[target-nums [I]], I]; }}}
2. The second question leetCode
Requirements: https://leetcode-cn.com/probl… I give you two non-empty lists that represent two non-negative integers. They store each number in reverse order, and each node can only store one digit. Input: l1 = [2, 3], l2 =,6,4 [5] output:,0,8 [7] : 342 + 465 = 807.
/* input: L1 = [2,4,3], L2 = [5,6,4] output: [7,0,8] explain: Function listNode (val) {this.val = val; this.val = val; this.val = val; this.val = val; this.val = val; this.val = val; this.val = val; this.val = val; this.val = val; this.val = val. this.next = null; } var addTwonumbers = function (L1, L2) {var Node = new ListNode("head"); Var cur = node; var cur = node; var cur = node; Var n = 0; var n = 0; var n = 0; Var sum = 0; var sum = 0; while (l1 || l2) { var n1 = l1 ? l1.val : 0; var n2 = l2? l2.val : 0; If n is less than 10, n is 0. SUM = n1 + n2 + n; ParseInt (sum / 10); parseInt(sum / 10); Next = new ListNode(sum %10); next = new ListNode(sum %10); // Set the next node of the current node, cur = cur.next; If (l1) {l1 = l1.next; } if (l2) { l2 = l2.next; }} // To add the last bit of a linked list to 10 or greater, If (n > 0) {cur.next = new, sum (n > 0) {cur.next = new, sum (n > 0) {cur.next = new, sum (n > 0) ListNode(n); } return node.next; };