You are viewing a single comment's thread. Return to all comments →
Here's my solution to make things clearer.
// Complete the whatFlavors function below. void whatFlavors(vector cost, int money) {
unordered_map<int,vector<int>> h;
for(int i=0; i < cost.size(); i++){ h[cost[i]].push_back(i+1); }
int ans = 0; for(int i=0;i<cost.size();i++){ int req = money - cost[i]; if(h.find(req)!=h.end()){ vector<int> temp = h[req]; for(int j=0;j<temp.size();j++){ if(temp[j] != i+1){ if(temp[j]<i+1) cout<<temp[j]<<" "<<i+1<<endl; else cout<<i+1<<" "<<temp[j]<<endl; ans = 1; break; } } } if(ans==1) break; }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
Here's my solution to make things clearer.
// Complete the whatFlavors function below. void whatFlavors(vector cost, int money) {
for(int i=0; i < cost.size(); i++){ h[cost[i]].push_back(i+1);
}
}