FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-NOTES/Algorithms/506.Relative-Ranks/solution.cpp at master · moranzcw/LeetCode-NOTES · GitHub
moranzcw
/
LeetCode-NOTES
Public
Notifications
You must be signed in to change notification settings
Fork
77
Star
201
Code
Issues
1
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-NOTES
/
Algorithms
/
506.Relative-Ranks
/
solution.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
26 lines (24 loc) · 760 Bytes
Breadcrumbs
LeetCode-NOTES
/
Algorithms
/
506.Relative-Ranks
/
solution.cpp
Copy path
File metadata and controls
26 lines (24 loc) · 760 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
bool
cmp
(pair<
int
,
int
> i, pair<
int
,
int
> j){
return
j.
first
< i.
first
;
}
class
Solution
{
public:
vector<string>
findRelativeRanks
(vector<
int
>& nums) {
vector<pair<
int
,
int
> > mapp;
for
(
int
i=
0
;i<nums.
size
();i++){
mapp.
push_back
(pair<
int
,
int
>(nums[i],i));
}
sort
(mapp.
begin
(), mapp.
end
(), cmp);
vector<string>
str
(nums.
size
());
for
(
int
i=
0
;i<mapp.
size
();i++){
str[mapp[i].
second
] =
to_string
(i +
1
);
}
if
(mapp.
size
() >
0
)
str[mapp[
0
].
second
] =
"
Gold Medal
"
;
if
(mapp.
size
() >
1
)
str[mapp[
1
].
second
] =
"
Silver Medal
"
;
if
(mapp.
size
() >
2
)
str[mapp[
2
].
second
] =
"
Bronze Medal
"
;
return
str;
}
};
Back
|
FazBrowse Home
|
New Git URL