problem

506. Relative Ranks

solution1:使用优先队列;

掌握priority_queuepair的使用;

class Solution {
public:
vector<string> findRelativeRanks(vector<int>& nums) {
priority_queue<pair<int, int>> myqueue;//
for(int i=; i<nums.size(); i++)
{
myqueue.push(pair(nums[i], i));//
}
vector<string> ans(nums.size(), "");//
int idx = , cnt = ;
for(int i=; i<nums.size(); i++)
{
idx = myqueue.top().second;//
myqueue.pop();
if(cnt==) ans[idx] = "Gold Medal";//
else if(cnt==) ans[idx] = "Silver Medal";
else if(cnt==) ans[idx] = "Bronze Medal";
else ans[idx] = to_string(cnt);
cnt++;
}
return ans; }
};

solution2: 使用映射map;

参考

1. Leetcode_506. Relative Ranks;

【leetcode】506. Relative Ranks的更多相关文章

  1. 【LeetCode】506. Relative Ranks 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序 argsort 堆 日期 题目地址:https ...

  2. 【leetcode】1122. Relative Sort Array

    题目如下: Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 ar ...

  3. 【LeetCode】392. Is Subsequence 解题报告(Python)

    [LeetCode]392. Is Subsequence 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/is-subseq ...

  4. 【LeetCode】86. Partition List 解题报告(Python)

    [LeetCode]86. Partition List 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http:// ...

  5. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  6. 【Leetcode】Pascal&#39;s Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  7. 53. Maximum Subarray【leetcode】

    53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...

  8. 27. Remove Element【leetcode】

    27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...

  9. 【刷题】【LeetCode】007-整数反转-easy

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...

随机推荐

  1. 在 Queue 中 poll()和 remove()有什么区别?(未完成)

    在 Queue 中 poll()和 remove()有什么区别?(未完成)

  2. Educational Codeforces Round 76 (Rated for Div. 2) D

    D题 原题链接 题意:就是给你n个怪兽有一个属性(攻击力),m个英雄,每个英雄有两种属性(分别为攻击力,和可攻击次数),当安排最好的情况下,最少的天数(每选择一个英雄出战就是一天) 思路:因为怪兽是不 ...

  3. [GDOI2014]采集资源

    题目概述 题目描述 魔兽争霸3中,战略资源的采集通过使用农民.苦工.小精灵以及寺僧来进行. 在魔兽争霸4的开发中,玻璃渣觉得这种模式太过单一,于是他们想添加更多的单位来使采集的模式更加丰富. 在新的模 ...

  4. PHP中将二维数组 转换成字符串

    function arr_to_str($arr) { $t ='' ; foreach ($arr as $v) { $v = join(",",$v); // 可以用implo ...

  5. Robot Framework--运行pybot时出错

    1.在Execution Profile中选择 pybot,点击 start,报错,找不到指定文件 2.在cmd中运行pybot.bat也是报错---pybot is not define 3.找到p ...

  6. Nginx中ngx_http_fastcgi_module

    转发请求到 FastCGI 服务器器,不不⽀支持 php 模块⽅方式指令:15.1 fastcgi_pass设置 fastcgi 服务器器的地址.地址可以指定为域名或 IP 地址,以及端⼝口Synta ...

  7. C# 安全性

    一.标识和Principal static void Main(string[] args) { AppDomain.CurrentDomain.SetPrincipalPolicy(System.S ...

  8. django加载本地html

    django加载本地html from django.shortcuts import render from django.http import HttpResponse from django. ...

  9. 关于class

    1.使用#include分离函数的定义与实现 c语言可以在xxx.h中定义函数,然后在xxx.cpp中实现函数: 在需要用到这些函数时,只要用#include引入xxx.h即可,这样就不用将所有代码全 ...

  10. [BJWC2008]王之财宝

    嘟嘟嘟 如果没有限制,而且必须选\(m\)件的话,就是隔板法\(C_{n + m - 1} ^ {m - 1}\)了.现在要选至多\(m\)件,那么就相当于新增一个板儿,分出的新的盒子表示" ...