We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
voidsolve(vector<int>arr,intmoney){// Complete this functionintfirstpick=0;intsecondpick;unordered_map<int,int>costTofavor;for(inti=0;i<arr.size();i++){secondpick=i;if(costTofavor.count(money-arr[i])){firstpick=costTofavor[money-arr[i]];cout<<firstpick+1<<" "<<secondpick+1<<endl;return;}costTofavor[arr[i]]=i;}}
My C++ approch to this question. Inspired by leetcode one-pass hash table solution.
Hash Tables: Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
My C++ approch to this question. Inspired by leetcode one-pass hash table solution.