leetcode

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

commit253e75ebe7bb220916faa5ca981305a422caec32
parent1e6a5a481a66d788a6afb603324e805301aed129
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateWed, 8 May 2024 16:06:07 +0200

Daily Problem

Diffstat:
AProblems/0506.cpp|+++++++++++++++++++
MREADME.md|+

2 files changed, 20 insertions(+), 0 deletions(-)


diff --git a/Problems/0506.cpp b/Problems/0506.cpp

@@ -0,0 +1,19 @@

class Solution {
public:
vector<string> findRelativeRanks(const vector<int> &score) const {
static const char *medal[] = {"Gold Medal", "Silver Medal", "Bronze Medal"};
static int index[10001];
const int n = size(score);
iota(index, index + n, 0);
sort(index, index + n, [&score](int a, int b) { return score[a] > score[b]; });
vector<string> res(n);
for (int i = 0; i < n; i++)
res[index[i]] = to_string(i + 1);
for (int i = 0; i < min(n, 3); i++)
res[index[i]] = medal[i];
return res;
}
};

diff --git a/README.md b/README.md

@@ -359,6 +359,7 @@ for solving problems.

| 0501 | Easy | [Find Mode in Binary Search Tree](Problems/0501.cpp) |
| 0502 | Hard | [IPO](Problems/0502.cpp) |
| 0503 | Medium | [Next Greater Element II](Problems/0503.cpp) |
| 0506 | Easy | [Relative Ranks](Problems/0506.cpp) |
| 0508 | Medium | [Most Frequent Subtree Sum](Problems/0508.cpp) |
| 0509 | Easy | [Fibonacci Number](Problems/0509.cpp) |
| 0511 | Easy | [Game Play Analysis I](Problems/0511.cpp) |