c++ two priority_queue solution and beat 98%

  • 0

    It seem that we need only to sort the shorter array, instead of the both two arrays. Using minimum heap will make it faster.

        int findContentChildren(vector<int>& g, vector<int>& s) {
            priority_queue<int, vector<int>, greater<int>> gq(g.begin(), g.end());
            priority_queue<int, vector<int>, greater<int>> sq(s.begin(), s.end());
            while(!gq.empty() && !sq.empty()) {
                if(gq.top() <= sq.top())
            return g.size()-gq.size();

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.