2. Two numbers add up to two non-empty lists, representing two non-negative integers. They store each number in reverse order, and each node can only store one digit.

You add the two numbers and return a linked list representing the sum in the same form.

You can assume that neither of these numbers starts with zero except for the number zero.

/** * Definition for singly-linked list. * function ListNode(val, next) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } */ /** * @param {ListNode} l1 * @param {ListNode} l2 * @return {ListNode} */ var addTwoNumbers = function(l1, l2) { let temp = 0; let head = null; let tail = null; while(l1 || l2){ let a = l1 ? l1.val : 0; let b = l2 ? l2.val : 0; let sum = a + b + temp; if(! head){ head = tail = new ListNode(sum%10, null); } else{ tail.next = new ListNode(sum%10); tail = tail.next; } temp = sum > 9 ? 1:0; if(l1){ l1 = l1.next; } if(l2){ l2 = l2.next; } } if(temp>0){ tail.next = new ListNode(temp); } return head; };

Given an array of integers nums and an integer target, find the two integers in the array whose sum is target and return their array index.

You can assume that each input corresponds to only one answer. However, the same element in the array cannot be repeated in the answer.

You can return the answers in any order.

/** * @param {number[]} nums * @param {number} target * @return {number[]} */ var twoSum = function(nums, target) { let numsSet = new Set(); for(let i=0; i<nums.length; i++){ let temp = target-nums[i] if(numsSet.has(temp)){ return [i,nums.indexOf(temp)] } numsSet.add(nums[i]) } };