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}; }
[LeetCode] 1. Two Sum
最新推荐文章于 2020-10-21 10:33:51 发布