../ Competitive Programming
-rw-r--r--aguang792 B1 min read

Leet Code Daily 2024-05-08 - Relative Ranks

Code

c++
unordered_map<int, string> kNames = {
    { 1, "Gold Medal" },
    { 2, "Silver Medal" },
    { 3, "Bronze Medal" },
};

class Solution {
public:
    vector<string> findRelativeRanks(vector<int>& score) {
        vector<int> sorted_score(score.begin(), score.end());
        sort(sorted_score.begin(), sorted_score.end());
        vector<string> ret;
        for (const auto s : score) {
            const int rank = 1 + distance(
                upper_bound(sorted_score.begin(), sorted_score.end(), s),
                sorted_score.end());
            ret.push_back(kNames.contains(rank) ? kNames[rank]: to_string(rank));
        }
        return ret;
    }
};

COMMAND INTERFACE

↑ ↓ navigate · Enter execute · Esc exit · try “whoami”

Loading filesystem…

:help aguang.xyz

A personal website disguised as an operating system.

Ctrl / Cmd + K
Command palette + full-text search
Tab / Shift + Tab
Move between links and controls
Enter
Open a focused link or search result
↑ / ↓ in search
Navigate search results
In a directory filter
Enter/Done or ↓ focuses a result; Esc clears the filter
Esc
Clear a search or close a window