https://leetcode.com/problems/two-sum/
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> m;
for (int i = 0; i < nums.size(); ++i)
{
int n = target - nums[i];
if (m.find(n) != m.end() && i != m[n]) return { i, m[n] };
else m.insert({nums[i], i});
}
return {0, 0};
}
};
GitHub : https://github.com/developeSHG/Algorithm-LeetCode/commit/0cfd8d69436f395f4246fdac3f9c019f161802fc
'Coding Test > LeetCode' 카테고리의 다른 글
[LeetCode] (Strings) Lv Easy. First Unique Character in a String (0) | 2023.02.06 |
---|---|
[LeetCode] (Array) Lv Easy. Contains Duplicate (0) | 2023.02.06 |
[LeetCode] (Array) Lv Easy. Rotate Array (0) | 2023.01.31 |
[LeetCode] (Design) Lv Easy. Shuffle an Array (0) | 2023.01.25 |
[LeetCode] (Math) Lv Easy. Fizz Buzz (0) | 2023.01.22 |
댓글