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. 分享一个我改进过的ocr算法

    https://github.com/zhangbo2008/chineseOCR-jingjianban 欢迎大家前来拍砖

  2. python_datetime模块和time模块

    1.datetime模块 获取当前时间: import datetime # 获取当前时间 ctime = datetime.datetime.now() print(ctime) 只显示:年-月-日 ...

  3. C语言I作业12一学期总结

    一.我学到的内容 二.我的收获 作业 收获 C语言I博客作业01 学会了编程"Hello word" C语言I博客作业02 安装编译器,将代码建立在自己的文件里面 C语言I博客作业 ...

  4. 使用jaxb用xsd生成java类

    命令: xjc -p 包的路径 xsd的名字.xsd -d 目标的文件夹 具体详细见: http://www.iteye.com/topic/1118082

  5. 慕课网SSMOA办公系统

    目录 需求分析 1 用例图 系统设计 包及全局配置 数据库设计 工具类 具体功能实现 1 dao层功能实现 2 编码过滤器及登陆拦截器 3 单元测试 遇到的问题总结 1 新建一个Modul不会打开新页 ...

  6. select([[data],fn])

    select([[data],fn]) 概述 当 textarea 或文本类型的 input 元素中的文本被选择时,会发生 select 事件.大理石平台生产厂 这个函数会调用执行绑定到select事 ...

  7. (转)实验文档1:跟我一步步安装部署kubernetes集群

    实验环境 基础架构 主机名 角色 ip HDSS7-11.host.com k8s代理节点1 10.4.7.11 HDSS7-12.host.com k8s代理节点2 10.4.7.12 HDSS7- ...

  8. 把字符串当做js代码执行的方法

    字符串还能当做javascript代码来执行?你能想到哪些方法? 1.setInterval("要执行的字符串",500);window对象的方法既可以传字符串,也可以传函数.该函 ...

  9. 1937:【06NOIP普及组】数列

    woc 太捞了简直捞的一匹 我居然会写博客 反正呀没有人看 随便写写喽

  10. Django基础之中间件

    1. 引入 在之前学习的过程中,已经学会了给视图函数加装饰器来判断用户是否登录,把没有登录的用户请求跳转到登录页面. 我们通过给几个特定视图函数加装饰器实现了这个需求. 但是以后添加的视图函数可能也需 ...