solve problems| Two Sum

the description:

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to the target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

You can return the answer in any order.

the first step:

understanding the issue:

the second step:

code writing

class Solution {
    public int[] twoSum(int[] nums, int target) {
    Hashtable<Integer, Integer> hashTable = new Hashtable<Integer, Integer>();
      int i = 0;
      while ((i < nums.length) && (hashTable.get(nums[i]) == null)) {      
        hashTable.put(target - nums[i], i);
        i++;
      }
      if (i < nums.length) {
        return new int[]{hashTable.get(nums[i]),i};
      } 
      return null;       
    }
};