-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1331.cpp
37 lines (37 loc) · 847 Bytes
/
1331.cpp
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
27
28
29
30
31
32
33
34
35
36
37
class Solution {
public:
vector<int> arrayRankTransform(vector<int>& arr)
{
priority_queue<int,vector<int> , greater<int>> pq;
for(int i = 0; i < arr.size(); i++)
{
pq.push(arr[i]);
}
int i = 1;
vector<int> ans;
if(arr.size() == 0)
return ans;
int val = pq.top();
pq.pop();
unordered_map<int,int> mp;
mp[val] = i;
while(!pq.empty())
{
if(val == pq.top())
{
mp[val] = i;
}
else if(val < pq.top())
{
val = pq.top();
mp[val] = ++i;
}
pq.pop();
}
for(int i = 0; i < arr.size(); i++)
{
ans.push_back(mp[arr[i]]);
}
return ans;
}
};