看有多少对,而不是有没有
public class Solution {
public int[] twoSum(int[] nums, int target) {
int count = 0;
if(nums == null || nums.length == 0)
{
return count;
}
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
for(int i = 0; i < nums.length; i++)
{
if(map.containsKey(target - nums[i]))
{
count++;
}
else
{. From 1point 3acres bbs
map.put(nums[i], i);
}
}
return count;
}
}