forked from lzl124631x/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths2.cpp
More file actions
20 lines (20 loc) · 661 Bytes
/
Copy paths2.cpp
File metadata and controls
20 lines (20 loc) · 661 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// https://discuss.leetcode.com/topic/77912/c-easy-to-understand
class Solution {
public:
vector<string> findRelativeRanks(vector<int>& nums) {
priority_queue<pair<int, int>> q;
for (int i = 0; i < nums.size(); ++i) q.push({ nums[i], i });
int rank = 1;
vector<string> ans(nums.size());
while (q.size()) {
string &s = ans[q.top().second];
q.pop();
if (rank == 1) s = "Gold Medal";
else if (rank == 2) s = "Silver Medal";
else if (rank == 3) s = "Bronze Medal";
else s = to_string(rank);
++rank;
}
return ans;
}
};