1. Two Sum
Easy · Array
Given an array of numbers and a target sum, find the indices of the two numbers that add up to the target. You can assume each input has exactly one solution, and you cannot use the same element twice. Your input is [nums, target] where nums is an array of integers and target is an integer. Return an array of two indices [i, j] where i < j and nums[i] + nums[j] = target.
Examples
Example 1 Input: [[2, 7, 11, 15], 9] Output: [0, 1] Explanation: nums[0] + nums[1] === 9
Example 2 Input: [[3, 2, 4], 6] Output: [1, 2] Explanation: nums[1] + nums[2] === 6
Constraints
- Standard input/output constraints apply