Hi. Here's my solution for the Two Sum problem using a Hash table.

Adding each element to the Hash table takes linear time (O(n)). I store each element in the array as the key and its position as the value. The idea is to find the key value (target - index1) if it's not null (it exists), then index2 is the value of that key. Each lookup takes constant time (O(1)) and in the worst case, it'll run n times.

Any comments or improvements are welcome.

Cheers.

```
import java.util.Hashtable;
public class Solution {
public int[] twoSum(int[] numbers, int target) {
int[] solution = new int[2];
Hashtable<Integer, Integer> H = new Hashtable<Integer,Integer> (numbers.length);
// O(n) time for adding each element to the Hash table.
for(int i=0; i<numbers.length; i++) {
H.put(numbers[i], i);
}
// Lookup for element index2 such that index2==(target-index1) (O(1))
// O(1) for each lookup, O(n) total.
for(int i=0; i<numbers.length; i++) {
if(H.get(target-numbers[i]) != null && H.get(target-numbers[i])!=i) {
solution[0] = i+1;
solution[1] = H.get(target - numbers[i]) +1;
break;
}
else continue;
}
return solution;
}
}
```