【leetcode】506. Relative Ranks
problem
solution1:使用优先队列;
掌握priority_queue 和 pair的使用;
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的更多相关文章
- 【LeetCode】506. Relative Ranks 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序 argsort 堆 日期 题目地址:https ...
- 【leetcode】1122. Relative Sort Array
题目如下: Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 ar ...
- 【LeetCode】392. Is Subsequence 解题报告(Python)
[LeetCode]392. Is Subsequence 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/is-subseq ...
- 【LeetCode】86. Partition List 解题报告(Python)
[LeetCode]86. Partition List 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http:// ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【Leetcode】Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...
- 53. Maximum Subarray【leetcode】
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...
- 27. Remove Element【leetcode】
27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...
- 【刷题】【LeetCode】007-整数反转-easy
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...
随机推荐
- Paper Reading:Receptive Field Block Net for Accurate and Fast Object Detection
论文:Receptive Field Block Net for Accurate and Fast Object Detection 发表时间:2018 发表作者:(Beihang Universi ...
- SmtpClient 发送邮件
利用SmtpClient 代码发送邮件. 简单测试代码: static void Main(string[] args) { MailMessage msg = new MailMessage(); ...
- python学习之基础入门,安装,字符串,数据转换,三元运算符
python基础 我们要开始学习新的编程语言了,加油~~ python是“世界上最好的语言”,学习它当然是认为它是最好的所以我们才学(人生苦短我学python),python运用于不同的领域,采集分析 ...
- 大数据之路week05--day01(I/O流阶段一 之File)
众所周知,我们电脑中有许许多多的文件夹和文件,文件的形式也有许多不同的格式,文件夹中也可以新建文件夹的存在,也就是多层的一步一步的嵌套. 我们想要实现I/O操作,就必须知道硬盘上文件的表现形式. 而J ...
- jQuery匿名函数和自定义插件
https://www.cnblogs.com/joey0210/p/3408349.html (function($){ //do something; })(jQuery);
- jQuery序列化乱码解决
query之提交序列化表单(serialize)及乱码处理1 提交乱码处理JSP文件声明如下 <%@ page language="java" pageEncoding=&q ...
- 15分钟入门Markdown
一.标题一 标题三 标题六 # 一.标题一 ### 标题三 ###### 标题六 二.字体 1.普通字体 字体加粗 斜体 斜体加粗 删除线 1.普通字体 **字体加粗** *斜体* ***斜体加粗** ...
- Python 2--序列
- [Luogu] 高斯消元法
https://www.luogu.org/problemnew/show/P3389 模拟,消元 #include <bits/stdc++.h> #define DB double ; ...
- Luogu5327【ZJOI2019】语言【树上差分,线段树合并】
题目大意 给定一棵$n$个节点的树,维护$n$个集合,一开始第$i$个集合只有节点$i$.有$m$个操作,每次操作输入一个$(u,v)$,表示将$(u,v)$这条链上所有点所属的集合合并.求有多少个无 ...