Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector<int> twoSum(vector<int>& nums, int target) {
- unordered_map<int, int> indices;
- for (int i = 0; i < nums.size(); i++) {
- if (indices.find(target - nums[i]) != indices.end()) {
- return {indices[target - nums[i]], i};
- }
- indices[nums[i]] = i;
- }
- return {};
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement