6ms c++ using priority_queue


  • 0
    J
    class Solution {
    private:
        long long f(int x, int a, int b, int c)
        {
            return a*x*x+b*x+c;
        }
        
    public:
        vector<int> sortTransformedArray(vector<int>& nums, int a, int b, int c) {
            auto compare=[](int a, int b){
                return a>b;
            };
            int len=nums.size();
            priority_queue<int, vector<int>, decltype(compare)> Q(compare);
            for(int i=0; i<len; i++)
            {
                Q.push(f(nums[i], a, b, c));
            }
            
            vector<int> ans;
            while(!Q.empty())
            {
                ans.push_back(Q.top());
                Q.pop();
            }
            return ans;
        }
    };
    

Log in to reply
 

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