###### LeetCode-Two Sum-解题报告

Given an array of integers, find two numbers such that they add up to a specific target number.

The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based.

You may assume that each input would have exactly one solution.

Input: numbers={2, 7, 11, 15}, target=9
Output: index1=1, index2=2

class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
map<int, vector<int> >Hash;
vector<int>ans;
int i = 1;
for (auto &item : nums)
{
Hash[item].push_back(i++);
}
i = 1;
for (auto &item : nums)
{
vector<int>& tmp = Hash[target - item];
if (!tmp.empty())
{
for (auto &index : tmp)
{
if (index != i)
{
ans.push_back(i);
ans.push_back(index);
return ans;
}
}
}
i++;
}
return ans;
}
};

#### CF(D. Fibonacci Sums)dp计数

2014-06-24 21:15:08

#### LeetCode-Minimum Size Subarray Sum-解题报告

2015-07-08 18:12:41

#### bzoj1534: [POI2005]Sum- Fibonacci sums

2017-06-03 21:34:03

#### poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告

2009年10月06日 9KB 下载

#### NOIP2016提高组复赛解题报告

2016-11-27 22:28:49

#### C语言解题报告模板

2016-09-17 11:10:44

#### ZOJ解题报告ZOJ解题报告

2010年08月02日 282KB 下载

#### LeetCode-Two Sum

2014-03-22 02:13:21

#### leetcode-two Sum

2016-04-16 10:09:05

#### acm解题报告.rar

2009年03月18日 10MB 下载

## 不良信息举报

LeetCode-Two Sum-解题报告