Back

Two Sum

Description

Fix the incorrect code to pass all the test cases.

Given an array of integers nums and an integer target, return the indices i and j such that nums[i] + nums[j] == target and i != j. You may assume that every input has exactly one pair of indices i and j that satisfy the condition. Return the answer with the smaller index first.

  1. nums = [2, 7, 11, 15]

    target = 9

    expected = [0, 1]

  2. nums = [3, 2, 4]

    target = 6

    expected = [1, 2]