Skip to content

Commit 177af59

Browse files
committed
2323 new algo added.
1 parent 7e066b3 commit 177af59

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

2001-2500/2323-Find-Minimum-Time-to-Finish-All-Jobs-II/cpp-2323/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ project(cpp_2323)
33

44
set(CMAKE_CXX_STANDARD 14)
55

6-
add_executable(cpp_2323 main.cpp)
6+
add_executable(cpp_2323 main2.cpp)

2001-2500/2323-Find-Minimum-Time-to-Finish-All-Jobs-II/cpp-2323/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using namespace std;
1010

1111

12-
/// Binary Search
12+
/// Binary Search + Greedy
1313
/// Time Complexity: O(nlogn + nlog(max_jobs))
1414
/// Space Complexity: O(1)
1515
class Solution {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// Source : https://leetcode.com/problems/find-minimum-time-to-finish-all-jobs-ii/
2+
/// Author : liuyubobobo
3+
/// Time : 2022-07-01
4+
5+
#include <iostream>
6+
#include <vector>
7+
#include <algorithm>
8+
9+
using namespace std;
10+
11+
12+
/// Greedy
13+
/// Time Complexity: O(nlogn)
14+
/// Space Complexity: O(1)
15+
class Solution {
16+
public:
17+
int minimumTime(vector<int>& jobs, vector<int>& workers) {
18+
19+
sort(jobs.begin(), jobs.end());
20+
sort(workers.begin(), workers.end());
21+
22+
int res = 0;
23+
for(int i = 0; i < jobs.size(); i ++)
24+
res = max(res, jobs[i] / workers[i] + !!(jobs[i] % workers[i]));
25+
return res;
26+
}
27+
};
28+
29+
30+
int main() {
31+
32+
vector<int> jobs1 = {5, 2, 4}, workers1 = {1, 7, 5};
33+
cout << Solution().minimumTime(jobs1, workers1) << '\n';
34+
// 2
35+
36+
return 0;
37+
}

0 commit comments

Comments
 (0)