• + 3 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.

    // VARIABLES:
    int n;
    list<int> S; // List of sock colors
    int input;
    int pairs = 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;
    
    return 0;
    }