Skip to content

Commit f85f6c0

Browse files
authored
Create 1235. Maximum Profit in Job Scheduling
1 parent 1b290f0 commit f85f6c0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public int jobScheduling(int[] startTime, int[] endTime, int[] profit) {
3+
int n = startTime.length;
4+
int[][] jobs = new int[n][3];
5+
for(int i=0;i<n;i++){
6+
jobs[i] = new int[]{startTime[i],endTime[i],profit[i]};
7+
}
8+
9+
Arrays.sort(jobs,(a,b) -> a[1] - b[1]);
10+
11+
TreeMap<Integer,Integer> dp = new TreeMap<>();
12+
dp.put(0,0);
13+
14+
for(int[] job:jobs){
15+
int val = job[2] + dp.floorEntry(job[0]).getValue();
16+
if(val>dp.lastEntry().getValue()){
17+
dp.put(job[1],val);
18+
}
19+
}
20+
21+
return dp.lastEntry().getValue();
22+
}
23+
}

0 commit comments

Comments
 (0)