Untitled
class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { cin.tie(nullptr)->sync_with_stdio(0); unordered_map<int, int> mp; int numsSize = nums.size(); for (int i = 0; i < numsSize; ++i) { int rem = target - nums[i]; auto ele = mp.find(rem); if (ele == mp.end()) { mp[nums[i]] = i; } else { return {i, ele->second}; } } return {0, 0}; } };
Leave a Comment