leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0506.cpp (601B)


0 class Solution {
1 public:
2 vector<string> findRelativeRanks(const vector<int> &score) const {
3 static const char *medal[] = {"Gold Medal", "Silver Medal", "Bronze Medal"};
4 static int index[10001];
5 const int n = size(score);
7 iota(index, index + n, 0);
8 sort(index, index + n, [&score](int a, int b) { return score[a] > score[b]; });
10 vector<string> res(n);
11 for (int i = 0; i < n; i++)
12 res[index[i]] = to_string(i + 1);
13 for (int i = 0; i < min(n, 3); i++)
14 res[index[i]] = medal[i];
16 return res;
17 }
18 };