leetcode 1. 两数之和

把top 100重新刷一遍

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

 

posted @ 2020-07-03 22:00  qiujiejie  阅读(87)  评论(0编辑  收藏  举报