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. webpack4.0打包优化策略整理小结

    本文转载于:https://www.jb51.net/article/137449.htm 介绍了webpack4.0打包优化策略整理小结,分享给大家,具体如下: webapck4 新特性介绍-参考资 ...

  2. elk with docker-compose

    version: '2' services: elasticsearch: image: docker.calix.local:18080/docker-elasticsearch:6.2.2-1 # ...

  3. Spring boot dubbo+zookeeper 搭建------基于gradle项目的消费端与服务端分离实战

    1. Dubbo简介 Dubbo是Alibaba开源的分布式框架,是RPC模式的一种成熟的框架,优点是可以与Spring无缝集成,应用到我们的后台程序中.具体介绍可以查看Dubbo官网. 2. Why ...

  4. BZOJ 1458 / Luogu P4311 士兵占领 (上下界最小流 / 直接最大流)

    做法1:上下界最小流 先来一发上下界最小流,思路比较暴力,就是把行和列看作n+mn+mn+m个点,(i,j)(i,j)(i,j)如果能占领就从第iii行向第jjj列连一条边,上界为1下界为0;然后从s ...

  5. form表单 一个input时 回车自动提交

    问题描述 form表单中,如果当前表单只有一个input输入框时,单击回车会自动提交当前表单. 解决方案 在当前form表单中添加一个隐藏的input, <input style="d ...

  6. Oracle 后台进程(五)SMON进程

    转载自:刘相兵 Maclean Liu 文章 你所不知道的后台进程 SMON 功能   SMON(system monitor process)系统监控后台进程,有时候也被叫做 system clea ...

  7. python while for 语句

    while 语句: >>> x = >>> : ... x += ... print(x) ... for 语句: >>> words = ['a ...

  8. leetcode解题报告(2):Remove Duplicates from Sorted ArrayII

    描述 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ex ...

  9. Gym - 101955K Let the Flames Begin 约瑟夫环

    Gym - 101955KLet the Flames Begin  说实话,没怎么搞懂,直接挂两博客. 小飞_Xiaofei的约瑟夫问题(Josephus Problem)3:谁最后一个出列 小飞_ ...

  10. 7月清北学堂培训 Day 5

    今天是钟皓曦老师的讲授~ 动态规划 动态规划的三种实现方法: 1.递推: 2.递归: 3.记忆化: 举个例子: 斐波那契数列:0,1,1,2,3,5,8…… Fn = Fn-1 + Fn-2 1.我们 ...