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.
When you use the 'flip' function, won't you end up having many useless '0's that will consume the memory as it loops through them? I think it is a better idea to remove the colors as soon as you pair them.
// VARIABLES:intn;list<int>S;// List of sock colorsintinput;intpairs=0;cin>>n;while(cin>>input){if(find(S.begin(),S.end(),input)!=S.end()){pairs+=1;S.remove(input);S.remove(input);continue;}S.push_back(input);}cout<<pairs;return0;}
Sales by Match
You are viewing a single comment's thread. Return to all comments →
When you use the 'flip' function, won't you end up having many useless '0's that will consume the memory as it loops through them? I think it is a better idea to remove the colors as soon as you pair them.