Class Solution

java.lang.Object
g0501_0600.s0506_relative_ranks.Solution

public class Solution extends Object
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&rsquo;s rank is <code>&quot;Gold Medal&quot;</code>.</li> <li>The <code>2<sup>nd</sup></code> place athlete&rsquo;s rank is <code>&quot;Silver Medal&quot;</code>.</li> <li>The <code>3<sup>rd</sup></code> place athlete&rsquo;s rank is <code>&quot;Bronze Medal&quot;</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&rsquo;s rank is <code>&quot;x&quot;</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> [&ldquo;Gold Medal&rdquo;,&ldquo;Silver Medal&rdquo;,&ldquo;Bronze Medal&rdquo;,&ldquo;4&rdquo;,&ldquo;5&rdquo;]</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> [&ldquo;Gold Medal&rdquo;,&ldquo;5&rdquo;,&ldquo;Bronze Medal&rdquo;,&ldquo;Silver Medal&rdquo;,&ldquo;4&rdquo;]</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 Details

    • Solution

      public Solution()
  • Method Details

    • findRelativeRanks

      public String[] findRelativeRanks(int[] nums)