# [1. Two Sum](https://leetcode.com/problems/two-sum/)

# 思路
刚开始用暴力匹配，后来看了答案恍然大悟，hash会快很多。

# C++
``` C++
class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        map<int, int>mp;
        vector<int>ans;
        int len = nums.size();
        for(int i = 0; i < len; i++){
            if( mp.find(target - nums[i]) != mp.end()){
                ans.push_back(mp[target - nums[i]]);
                ans.push_back(i);
                return ans;
            }
            mp[nums[i]] = i;  
        }     
    }
};

```
