-
Notifications
You must be signed in to change notification settings - Fork 0
/
506.hpp
44 lines (37 loc) · 1.04 KB
/
506.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef LEETCODE_506_HPP
#define LEETCODE_506_HPP
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <numeric>
#include <stack>
#include <string>
using namespace std;
class Solution {
public:
vector<string> findRelativeRanks(vector<int> &nums) {
vector<int> index(nums.size());
iota(index.begin(), index.end(), 0);
sort(index.begin(), index.end(), [&nums](const int &l, const int &r) -> bool {
return nums[l] > nums[r];
});
vector<string> result(nums.size());
for (int i = 0; i < nums.size(); i++) {
if (i == 0) {
result[index[i]] = "Gold Medal";
} else if (i == 1) {
result[index[i]] = "Silver Medal";
} else if (i == 2) {
result[index[i]] = "Bronze Medal";
} else {
result[index[i]] = to_string(i + 1);
}
}
return result;
}
};
#endif //LEETCODE_506_HPP