public class Solution { public int[] twoSum(int[] nums, int target) { int[] defaultResult={0,0}; HashMap<Integer,Integer> map=new HashMap<Integer,Integer>(); for(int i=0;i<nums.length;i++){ if(map.get(target-nums[i])!=null){ int[] result={map.get(target-nums[i])+1,i+1}; return result; } map.put(nums[i],i); } return defaultResult; } }
原文:http://www.cnblogs.com/yuxiaofei/p/5103829.html