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. Mysql读写分离 及高可用高性能负载均衡实现

    什么是读写分离,说白了就是mysql服务器读的操作和写的操作是分开的,当然这个需要两台服务器,master负责写,slave负责读,当然我们可以使用多个slave,这样我们也实现了简单意义上的高可用和 ...

  2. PHP 获取上传文件的实际类型

    方案一: mime_content_type ( string $filename ) : string (PHP 4 >= 4.3.0, PHP 5, PHP 7) mime_content_ ...

  3. python----四种内置数据结构(dict、list、tuple、set)

    1.dict 无序,可更改 2.tuple 有序,不可更改 3.list 有序,可更改(增加,删除) 4.set 无序,可能改 {元素1,元素2,元素3.....}和字典一样都是用大括号定义,不过不同 ...

  4. Java并发包--LinkedBlockingDeque

    转载请注明出处:http://www.cnblogs.com/skywang12345/p/3503480.html LinkedBlockingDeque介绍 LinkedBlockingDeque ...

  5. duilib学习领悟(3)

    世上本无窗口,窗口只是人的眼睛和电脑屏幕及鼠标键盘相互操作后的视觉效果! 下面我们来看看我们之前讲过的代码: class CDuiFrameWnd : public CWindowWnd, publi ...

  6. 编译安装 openmcu

    1. install toolssudo apt-get install libtool autoconf flex bison automake pkg-config 2.yasm-1.3.0sed ...

  7. SpringBoot+JTA+Mybatis

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/sinat_36596988/article ...

  8. 牛客练习赛51 D题

    链接:https://ac.nowcoder.com/acm/contest/1083/D来源:牛客网 有一个草原可以用一个1~400的数轴表示.有n头羊和q个查询.每头羊的编号分别是1,2,3…n. ...

  9. sql server 函数学习

    sql server 创建函数 资料 https://docs.microsoft.com/zh-cn/sql/relational-databases/user-defined-functions/ ...

  10. SQL Server Report Server

    1.SQL Server Report Server是利用mircosoft的share point产品 在menu 打开Reporting Services Configuration进行配置,会自 ...