[LeetCode]506. Relative Ranks
[LeetCode]506. Relative Ranks
题目描述
思路
用map保存
计算res的时候直接逆序遍历map即可
代码
#include <iostream>
#include <string>
#include <vector>
#include <map>using namespace std;class Solution {
public:vector<string> findRelativeRanks(vector<int>& nums) {map<int, int> m;int rank = nums.size();int cnt = 1;for (int i = 0; i < nums.size(); ++i)m[nums[i]] = i;vector<string> res(m.size(), "");for (map<int, int>::reverse_iterator it = m.rbegin(); it != m.rend(); it++, cnt++) {if (cnt == 1) res[it->second] = "Gold Medal";else if (cnt == 2) res[it->second] = "Silver Medal";else if (cnt == 3) res[it->second] = "Bronze Medal";else res[it->second] = to_string(cnt);}return res;}
};int main() {vector<int> nums = { 5, 4, 3 };vector<string> res;Solution s;res = s.findRelativeRanks(nums);for (auto &p : res) {cout << p << " ";}cout << endl;system("pause");
}
[LeetCode]506. Relative Ranks相关推荐
- LeetCode | 506. Relative Ranks
Given scores of N athletes, find their relative ranks and the people with the top three highest scor ...
- LeetCode之Relative Ranks
1.题目 Given scores of N athletes, find their relative ranks and the people with the top three highest ...
- LeetCode Relative Ranks
今天做了大概四五道题,但觉着这道题是最值得分享的吧,Relative Ranks意思是相对排名问题,下面是题目具体内容,大家可以通过翻译试着做一下: Given scores of N athlete ...
- LeetCode 506. 相对名次(map)
1. 题目 给出 N 名运动员的成绩,找出他们的相对名次并授予前三名对应的奖牌. 前三名运动员将会被分别授予 "金牌","银牌" 和" 铜牌" ...
- leetcode 506. 相对名次(Java版)
题目 https://leetcode-cn.com/problems/relative-ranks/ 题解 思路主要是,将运动员一开始的位置记录下来,方便颁奖的时候去指定位置颁给指定的人. 先用ma ...
- leetcode 506 相对名次
https://leetcode-cn.com/problems/relative-ranks/ 题目 给你一个长度为nnn的整数数组scorescorescore,其中score[i]score[i ...
- LeetCode 简单算法题
使用Nodejs 抓取的LeetCode 简单算法题 一步一步来,先攻破所有简单的题目,有些题目不适合使用JS解决,请自行斟酌 Letcode 简单题汇总 104. Maximum Depth of ...
- Leetcode算法题-解法转载
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/fuxuemingzhu/article/details/85112591 作者: 负雪明烛 i ...
- LeetCode All in One 题目讲解汇总(持续更新中...)
原文地址:https://www.cnblogs.com/grandyang/p/4606334.html 终于将LeetCode的大部分题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开 ...
最新文章
- c#.net调用pdf2swf.exe将pdf文件转换为swf,vs中运行正常,布署IIS服务器部署转换后文字部分为空白...
- postgresql数据库的数据导出
- matlab图像显示时间,请问怎么把样点数变成时间显示在图像了里
- 消息队列NetMQ 原理分析2-IO线程和完成端口
- linux list 添加失败,linux运维实战案例之Argument list too long错误与解决方法
- linux查看目录下 开头,Linux下ls如何看到.开头的文件
- Tomcat Insufficient space for shared memory file
- 对于以太网口作为下一条路由的理解
- 大文件读取mmap磁盘映射
- Maven Dependency设置,详解!
- ps 毛发 边缘_PS技巧:毛发抠图调整边缘法
- 如何启用计算机睡眠功能,台式机睡眠如何开启
- SpringBoot-logback日志管理
- 谷歌插件EpubPress 将网页保存为电子书
- 【扬汤止沸,不如釜底抽薪】夜来风雨声,Lucene知多少?
- ILITEK touch driver
- 罗永浩、360 回应大规模裁员;阿里公布双 11 技术数据;苹果供应商受重挫 | 极客头条...
- 年度总结|回顾 2021,展望 2022
- 《算法笔记》—— 解决 排列组合问题 递归的灵活运用
- 量子计算机与人脑接口,首次实现25个量子接口之间量子纠缠 清华刷新纪录