Advertisement
vaibhav1906

Trial

Feb 27th, 2022
1,176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     vector<int> twoSum(vector<int>& nums, int target) {
  4.        
  5.         unordered_multimap <int, int> m;
  6.        
  7.         for(int i = 0; i<nums.size(); i++){
  8.             m.insert({nums[i],i});
  9.         }
  10.        
  11.         for(auto it= m.begin(); it!=m.end(); it++){
  12.             int rem = target - it->first;
  13.            
  14.             if(m.find(rem)!=m.end() && it->second != m.find(rem)->second){
  15.                 return {it->second, m.find(rem)->second};
  16.             }
  17.            
  18.         }
  19.        
  20.         return {};
  21.        
  22.     }
  23. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement