Original link: leetcode-cn.com/problems/tw…

Answer:

  1. The result is returned if the sum of two numbers is found to be target.
  2. Note that the second loop only iterates through the elements left after the first loop.
/** * @param {number[]} nums * @param {number} target * @return {number[]} */ var twoSum = function(nums, target) { for (let i = 0; i < nums.length - 1; I ++) {// iterate over the element after I for (let j = I + 1; j < nums.length; If (nums[I] + nums[j] === target) {return [I, j]; }}}};Copy the code