C++ Solution using Priority Queue


  • 1
    vector<string> findRelativeRanks(vector<int>& nums) {
        
       priority_queue<int> Q;
       for(int num : nums)
       Q.push(num);
       int count = 0; 
        vector<string> ans(nums.size());
        int temp;
        while(Q.size() > 0)
        {
            count++;
            temp = Q.top();
            Q.pop();
            for(int i=0;i<nums.size();i++)
                if(nums[i] == temp)
                {
                    if(count == 1)
                        ans[i] = "Gold Medal";
                    else if(count == 2)
                        ans[i] = "Silver Medal";
                    else if(count == 3)
                        ans[i] = "Bronze Medal";
                    else
                        ans[i] = to_string(count);
                    break;
                }
        }
        return ans;
    }

Log in to reply
 

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