g2o
1.两数之和.cpp
Go to the documentation of this file.
1 /*
2  * @lc app=leetcode.cn id=1 lang=cpp
3  *
4  * [1] 两数之和
5  *
6  * https://leetcode-cn.com/problems/two-sum/description/
7  *
8  * algorithms
9  * Easy (45.23%)
10  * Total Accepted: 279.2K
11  * Total Submissions: 617.3K
12  * Testcase Example: '[2,7,11,15]\n9'
13  *
14  * 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。
15  *
16  * 你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。
17  *
18  * 示例:
19  *
20  * 给定 nums = [2, 7, 11, 15], target = 9
21  *
22  * 因为 nums[0] + nums[1] = 2 + 7 = 9
23  * 所以返回 [0, 1]
24  *
25  *
26  */
27 class Solution {
28 public:
29  vector<int> twoSum(vector<int>& nums, int target) {
30  std::map<int, int> mapNum;
31  for(int i=0; i<nums.size(); i++) {
32  mapNum.insert(std::pair<int, int>(nums[i], i))
33  }
34  }
35 };
36 
vector< int > twoSum(vector< int > &nums, int target)