首页 > 其他分享 >LeetCode 1 两数之和

LeetCode 1 两数之和

时间:2022-09-05 17:45:22浏览次数:75  
标签:map target temp nums int LeetCode 两数

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int, int> map;
        for (int i = 0; i < nums.size(); i ++) {
            auto temp = map.find(target - nums[i]);
            if (temp != map.end()) return {temp->second, i};
            map.insert({nums[i], i}); 
        }

        return {};   
    }
};

标签:map,target,temp,nums,int,LeetCode,两数
From: https://www.cnblogs.com/hjy94wo/p/16658980.html

相关文章