package lc001_twosum;

import java.util.HashMap;

public class Solution {
    public int[] twoSum(int[] nums, int target) {
        int[] error = new int[] {-1, -1};
        if (nums.length < 2) {
            return error;
        }

        HashMap<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i], i);
        }

        for (int i = 0; i < nums.length; i++) {
            Integer j = map.get(target - nums[i]);
            if (j != null && i != j) { // error1: j!=null
                return new int[] {i, j};
            }
        }
        return error;
    }
}
@@ -43,16 +43,359 @@
 shMap;%0A%0A
+/**%0A * Given an array of integers, return indices of the two numbers such that they add up to a specific target.%0A * You may assume that each input would have exactly one solution.%0A * The return format had been changed to zero-based indices.%0A * Given nums = %5B2, 7, 11, 15%5D, target = 9, Because nums%5B0%5D + nums%5B1%5D = 2 + 7 = 9, return %5B0, 1%5D.%0A */%0A
 public c

leetcode-1 add two sum: fix bug