Given an array of integers, find two indices in the array where the values sum to a target. The first index must be less than the second index, and the indicies starts with 1, not 0.

Example

Array           Target    Result
[1, 3, 5, 7]    4         [1, 2]
[1, 3, 5, 7]    8         [1, 4] or [2, 3]
[2, 7, 8, 5]    9         [1, 2]
public class Solution {
    /*
     * @param numbers : An array of Integer
     * @param target : target = numbers[index1] + numbers[index2]
     * @return : [index1 + 1, index2 + 1] (index1 < index2)
     */
    public int[] twoSum(int[] numbers, int target) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < numbers.length; i++) {
            if (map.containsKey(target - numbers[i]))
                return new int[] {map.get(target - numbers[i]), i + 1};
            map.put(numbers[i], i + 1);
        }
        return null;
    }
}