-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1675.cpp
More file actions
30 lines (28 loc) · 783 Bytes
/
1675.cpp
File metadata and controls
30 lines (28 loc) · 783 Bytes
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
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
class Problem1675 {
public:
int minimumDeviation(vector<int>& nums) {
int MAX = INT_MIN, MIN = INT_MAX;
for (int i = 0; i < nums.size(); i++){
if(nums[i] % 2 == 1) nums[i] *= 2;
MAX = max(MAX, nums[i]);
MIN = min(MIN, nums[i]);
}
int minDev = MAX-MIN;
priority_queue<int> q;
for (int i: nums) q.push(i);
while(q.top() % 2 == 0){
int top = q.top();
q.pop();
minDev = min(minDev, top-MIN);
top /= 2;
MIN = min(MIN, top);
q.push(top);
}
minDev = min(minDev, q.top()-MIN);
return minDev;
}
};