vector<int> twoSum(vector<int>& nums, int target) { unordered_map<int,int> hash; int n=nums.size(); for(int i=0;i<n;++i) { if(hash[target-nums[i]]) return {i,hash[target-nums[i]]-1}; hash[nums[i]]=i+1; } return {0,0}; }
转载于:https://www.cnblogs.com/xLester/p/7570284.html