-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1235.规划兼职工作.java
34 lines (31 loc) · 916 Bytes
/
1235.规划兼职工作.java
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
/*
* @lc app=leetcode.cn id=1235 lang=java
*
* [1235] 规划兼职工作
*/
// @lc code=start
class Solution {
private static int max = 0;
public int jobScheduling(int[] startTime, int[] endTime, int[] profit) {
backtrack(0, 0, startTime, endTime, profit);
return max;
}
private static void backtrack(int start, int res, int[] startTime, int[] endTime, int[] profit) {
int length = startTime.length;
if (start >= length) {
max = Math.max(max, res);
return;
}
for (int i = start; i < length; i++) {
int right = endTime[i];
int next = i + 1;
while (next < length && startTime[next] < right) {
next++;
}
res += profit[i];
backtrack(next, res, startTime, endTime, profit);
res -= profit[i];
}
}
}
// @lc code=end