package problem.twosum;

import java.util.*;

public class TwoSum {
  public static int[] twoSum(int[] numbers, int target) {
    // 1. Initialization
    
    // 1.1 The result
    int[] result = new int[2];
    
    // 1.2 The count of numbers
    int n = numbers.length;
    
    // 1.3 The HashMap
    Map<Integer, Integer> hashMap = new HashMap<Integer, Integer>();
    
    // 2. Calculation

    // 2.1 Complement of the target, number value and index
    int numberComplement = 0;
    int indexComplement = 0;

    // 2.2 Loop through each element trying to find its complement
    for (int i = 0; i < n; i++) {
      numberComplement = target - numbers[i];
      if (hashMap.containsKey(numberComplement)) {
        indexComplement = hashMap.get(numberComplement);
        result[0] = indexComplement + 1;
        result[1] = i + 1;
        break;
      } else {
        hashMap.put(numbers[i], i);
      } 
    }
    
    // 3. Return
    return result;
  } // End of method twoSum()
} // End of class SolutionTwoSum

@@ -1,8 +1,498 @@
+/**%0A * Given an array of integers, find two numbers such that they add up to a%0A * specific target number.%0A *%0A * The function twoSum should return indices of the two numbers such that they%0A * add up to the target, where index1 must be less than index2. Please note%0A * that your returned answers (both index1 and index2) are not zero-based.%0A *%0A * You may assume that each input would have exactly one solution.%0A *%0A * Input: numbers=%7B2, 7, 11, 15%7D, target=9%0A * Output: index1=1, index2=2%0A */%0A%0A
 package 

Update TwoSum.java