# leetcode 1.Two Sum （水题，STL_map）

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

Example:

Given nums = [2, 7, 11, 15], target = 9,

Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].


class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
map<int,int>f;
vector<int>res;
int n = nums.size();
for(int i=0;i<n;i++) {
if(f.count(target-nums[i])) {
res.push_back(f[target-nums[i]]);
res.push_back(i);
return res;
}
f[nums[i]]=i;
}
}
};

#### B. Two Buttons

2015-03-04 18:01:48

#### LeetCode 1 Two Sum（unordered_map和map的区别）

2016-03-22 15:10:01

#### LeetCode题解--1. Two Sum(和为S的两个数字)

2016-01-27 22:32:25

#### 【LeetCode编程学习（C语言）】1.Two Sum

2016-03-28 13:39:40

#### 第二周leetcode水题

2017-03-07 13:36:45

#### Leetcode two sum java 解法

2014年03月13日 537B 下载

#### Leetcode 1.Two Sum

2016-06-25 18:39:45

#### 1.Two Sum Leetcode Python

2015-01-27 01:04:51

#### leetcode 1.Two sum

2017-07-18 21:27:33

#### [Leetcode] 1.Two Sum（unordered_map）

2017-11-20 11:19:39