您的位置:首页 > 其它

Amazon online assessment OA two sum (check how many 多少对)

2015-08-27 12:01 281 查看
看有多少对,而不是有没有

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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  亚马逊