Skip to content

Commit cdea173

Browse files
authored
Create 506. Relative Ranks (#474)
2 parents 32066f0 + 0dbb275 commit cdea173

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

506. Relative Ranks

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
vector<string> findRelativeRanks(vector<int>& a) {
4+
int n = a.size();
5+
vector<pair<int,int>> pairs;
6+
for(int i=0;i<n;i++)pairs.push_back({a[i],i});
7+
sort(pairs.begin(), pairs.end(), greater<pair<int,int>>());
8+
vector<string> res(n);
9+
for(int i=0;i<n;i++) {
10+
if(i==0)res[pairs[i].second]="Gold Medal";
11+
else if(i==1)res[pairs[i].second]="Silver Medal";
12+
else if(i==2)res[pairs[i].second]="Bronze Medal";
13+
else res[pairs[i].second] = to_string(i+1);
14+
}
15+
return res;
16+
}
17+
};

0 commit comments

Comments
 (0)