Skip to content

Commit af300e9

Browse files
authored
Create minimum-time-to-build-blocks.cpp
1 parent 30deb93 commit af300e9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

C++/minimum-time-to-build-blocks.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Time: O(nlogn)
2+
// Space: O(n)
3+
4+
class Solution {
5+
public:
6+
int minBuildTime(vector<int>& blocks, int split) {
7+
priority_queue<int, vector<int>, greater<int>> min_heap(blocks.cbegin(), blocks.cend());
8+
while (min_heap.size() != 1) {
9+
min_heap.pop();
10+
const auto y = min_heap.top(); min_heap.pop();
11+
min_heap.emplace(y + split);
12+
}
13+
return min_heap.top();
14+
}
15+
};

0 commit comments

Comments
 (0)