[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相关推荐

  1. LeetCode | 506. Relative Ranks

    Given scores of N athletes, find their relative ranks and the people with the top three highest scor ...

  2. LeetCode之Relative Ranks

    1.题目 Given scores of N athletes, find their relative ranks and the people with the top three highest ...

  3. LeetCode Relative Ranks

    今天做了大概四五道题,但觉着这道题是最值得分享的吧,Relative Ranks意思是相对排名问题,下面是题目具体内容,大家可以通过翻译试着做一下: Given scores of N athlete ...

  4. LeetCode 506. 相对名次(map)

    1. 题目 给出 N 名运动员的成绩,找出他们的相对名次并授予前三名对应的奖牌. 前三名运动员将会被分别授予 "金牌","银牌" 和" 铜牌" ...

  5. leetcode 506. 相对名次(Java版)

    题目 https://leetcode-cn.com/problems/relative-ranks/ 题解 思路主要是,将运动员一开始的位置记录下来,方便颁奖的时候去指定位置颁给指定的人. 先用ma ...

  6. leetcode 506 相对名次

    https://leetcode-cn.com/problems/relative-ranks/ 题目 给你一个长度为nnn的整数数组scorescorescore,其中score[i]score[i ...

  7. LeetCode 简单算法题

    使用Nodejs 抓取的LeetCode 简单算法题  一步一步来,先攻破所有简单的题目,有些题目不适合使用JS解决,请自行斟酌 Letcode 简单题汇总 104. Maximum Depth of ...

  8. Leetcode算法题-解法转载

    版权声明:本文为博主原创文章,未经博主允许不得转载.    https://blog.csdn.net/fuxuemingzhu/article/details/85112591 作者: 负雪明烛 i ...

  9. LeetCode All in One 题目讲解汇总(持续更新中...)

    原文地址:https://www.cnblogs.com/grandyang/p/4606334.html 终于将LeetCode的大部分题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开 ...

最新文章

  1. c#.net调用pdf2swf.exe将pdf文件转换为swf,vs中运行正常,布署IIS服务器部署转换后文字部分为空白...
  2. postgresql数据库的数据导出
  3. matlab图像显示时间,请问怎么把样点数变成时间显示在图像了里
  4. 消息队列NetMQ 原理分析2-IO线程和完成端口
  5. linux list 添加失败,linux运维实战案例之Argument list too long错误与解决方法
  6. linux查看目录下 开头,Linux下ls如何看到.开头的文件
  7. Tomcat Insufficient space for shared memory file
  8. 对于以太网口作为下一条路由的理解
  9. 大文件读取mmap磁盘映射
  10. Maven Dependency设置,详解!
  11. ps 毛发 边缘_PS技巧:毛发抠图调整边缘法
  12. 如何启用计算机睡眠功能,台式机睡眠如何开启
  13. SpringBoot-logback日志管理
  14. 谷歌插件EpubPress 将网页保存为电子书
  15. 【扬汤止沸,不如釜底抽薪】夜来风雨声,Lucene知多少?
  16. ILITEK touch driver
  17. 罗永浩、360 回应大规模裁员;阿里公布双 11 技术数据;苹果供应商受重挫 | 极客头条...
  18. 年度总结|回顾 2021,展望 2022
  19. 《算法笔记》—— 解决 排列组合问题 递归的灵活运用
  20. 量子计算机与人脑接口,首次实现25个量子接口之间量子纠缠 清华刷新纪录

热门文章

  1. 【Android】二进制图片和Bitmap的getPixel方法解析
  2. 深入OpenJDK源码-偏向锁的延时生效如何实现的
  3. 10款专为设计师打造的热门工具清单
  4. 压测--部署jp@gc - PerfMon Metrics Collector
  5. 用Excel求线性回归方程
  6. 【SQL Server】模糊查询
  7. 校园招聘可以报考哪些岗位?
  8. html input hiden,input hidden属性
  9. dedecms 自定义表单html,dedecms自定义表单和自定义表单如何用自己模板教程
  10. 借钱赚钱花钱6点认识