class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int>ans;
unordered_map<int,int>m;
for(int i=0; i<nums.size(); i++){
int curr=target-nums[i];
auto it=m.find(curr);
if (it != m.end()){
ans.push_back(m[curr]);
ans.push_back(i);
return ans;
}
else m[nums[i]] = i;
}
return ans;
}
};
'Algorithm ๐ง๐ปโ๐ป > Leetcode' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Leetcode,c++] Search Insert Position (0) | 2021.11.09 |
---|---|
[Leetcode,c++] Find the City With the Smallest Number of Neighbors at a Threshold Distance (0) | 2021.11.07 |
[Leetcode,c++] Combination Sum (0) | 2021.11.07 |
[Leetcode,c++] Multiply-Strings (0) | 2021.11.07 |
[Leetcode,c++] Longest Common Subsequence (0) | 2021.10.23 |
[Leetcode,c++] Robot Bounded In Circle (0) | 2021.10.23 |
๋๊ธ