/* * @lc app=leetcode id=1 lang=java * * [1] Two Sum */ class Solution { public int[] twoSum(int[] nums, int target) { int[] res = new int[2]; if (nums == null || nums.length <= 1) { return res; } Map<Integer, Integer> m = new HashMap<>();
for (int i = 0; i < nums.length; i++) { Integer pst = m.get(nums[i]); if (pst == null) { m.put(target - nums[i], i); } else { res[0] = pst; res[1] = i; break; }