“`” 考察点:数组
<pre><code class=""language-java"" lang=""java"">public int[] twoSum(int[] nums, int target) {
HashMap<Integer, Integer> map =new HashMap<Integer, Integer>();
int[] a = new int[2];
map.put(nums[0], 0);
for (int i = 1; i < nums.length;i++) {
if (map.containsKey(target – nums[i])) {
a[0] = map.get(target -nums[i]);
a[1] = i;
return a;
} else {
map.put(nums[i], i);
}
}
return a;
}
</code></pre>
<pre><code> "“`
Was this helpful?
0 /
0