Package g0501_0600.s0506_relative_ranks
Class Solution
java.lang.Object
g0501_0600.s0506_relative_ranks.Solution
506 - Relative Ranks.<p>Easy</p>
<p>You are given an integer array <code>score</code> of size <code>n</code>, where <code>score[i]</code> is the score of the <code>i<sup>th</sup></code> athlete in a competition. All the scores are guaranteed to be <strong>unique</strong>.</p>
<p>The athletes are <strong>placed</strong> based on their scores, where the <code>1<sup>st</sup></code> place athlete has the highest score, the <code>2<sup>nd</sup></code> place athlete has the <code>2<sup>nd</sup></code> highest score, and so on. The placement of each athlete determines their rank:</p>
<ul>
<li>The <code>1<sup>st</sup></code> place athlete’s rank is <code>"Gold Medal"</code>.</li>
<li>The <code>2<sup>nd</sup></code> place athlete’s rank is <code>"Silver Medal"</code>.</li>
<li>The <code>3<sup>rd</sup></code> place athlete’s rank is <code>"Bronze Medal"</code>.</li>
<li>For the <code>4<sup>th</sup></code> place to the <code>n<sup>th</sup></code> place athlete, their rank is their placement number (i.e., the <code>x<sup>th</sup></code> place athlete’s rank is <code>"x"</code>).</li>
</ul>
<p>Return an array <code>answer</code> of size <code>n</code> where <code>answer[i]</code> is the <strong>rank</strong> of the <code>i<sup>th</sup></code> athlete.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> score = [5,4,3,2,1]</p>
<p><strong>Output:</strong> [“Gold Medal”,“Silver Medal”,“Bronze Medal”,“4”,“5”]</p>
<p><strong>Explanation:</strong> The placements are [1<sup>st</sup>, 2<sup>nd</sup>, 3<sup>rd</sup>, 4<sup>th</sup>, 5<sup>th</sup>].</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> score = [10,3,8,9,4]</p>
<p><strong>Output:</strong> [“Gold Medal”,“5”,“Bronze Medal”,“Silver Medal”,“4”]</p>
<p><strong>Explanation:</strong> The placements are [1<sup>st</sup>, 5<sup>th</sup>, 3<sup>rd</sup>, 2<sup>nd</sup>, 4<sup>th</sup>].</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == score.length</code></li>
<li><code>1 <= n <= 10<sup>4</sup></code></li>
<li><code>0 <= score[i] <= 10<sup>6</sup></code></li>
<li>All the values in <code>score</code> are <strong>unique</strong>.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
findRelativeRanks
-