You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
496 B
C++
24 lines
496 B
C++
/*
|
|
* @lc app=leetcode id=1 lang=cpp
|
|
*
|
|
* [1] Two Sum
|
|
*/
|
|
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
class Solution
|
|
{
|
|
public:
|
|
vector<int> twoSum(vector<int> &nums, int target)
|
|
{
|
|
unordered_map<int, int> m;
|
|
for (int i = 0; i < nums.size(); i++)
|
|
{
|
|
auto ite = m.find(target - nums[i]);
|
|
if (ite != m.end())
|
|
return {ite->second, i};
|
|
m[nums[i]] = i;
|
|
}
|
|
return {0, 0};
|
|
}
|
|
};
|