Skip to content

Commit 5205538

Browse files
author
haotf
committed
feat: 规划兼职工作
1 parent 29010b0 commit 5205538

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Diff for: 1235.规划兼职工作.java

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* @lc app=leetcode.cn id=1235 lang=java
3+
*
4+
* [1235] 规划兼职工作
5+
*/
6+
7+
// @lc code=start
8+
class Solution {
9+
private static int max = 0;
10+
11+
public int jobScheduling(int[] startTime, int[] endTime, int[] profit) {
12+
backtrack(0, 0, startTime, endTime, profit);
13+
return max;
14+
}
15+
16+
private static void backtrack(int start, int res, int[] startTime, int[] endTime, int[] profit) {
17+
int length = startTime.length;
18+
if (start >= length) {
19+
max = Math.max(max, res);
20+
return;
21+
}
22+
for (int i = start; i < length; i++) {
23+
int right = endTime[i];
24+
int next = i + 1;
25+
while (next < length && startTime[next] < right) {
26+
next++;
27+
}
28+
res += profit[i];
29+
backtrack(next, res, startTime, endTime, profit);
30+
res -= profit[i];
31+
}
32+
}
33+
}
34+
// @lc code=end

0 commit comments

Comments
 (0)