Skip to content

Commit a12a4e7

Browse files
authored
Update Solution2.ts
1 parent 8b27d05 commit a12a4e7

File tree

1 file changed

+7
-10
lines changed
  • solution/0800-0899/0826.Most Profit Assigning Work

1 file changed

+7
-10
lines changed
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
function maxProfitAssignment(difficulty: number[], profit: number[], worker: number[]): number {
2-
const wMax = Math.max(...worker);
3-
const jobs = Array(wMax + 1).fill(0);
2+
const m = Math.max(...difficulty);
3+
const f = Array(m + 1).fill(0);
44
const n = profit.length;
5-
6-
for (let i = 0; i < n; i++) {
5+
for (let i = 0; i < n; ++i) {
76
const d = difficulty[i];
8-
if (d <= wMax) jobs[d] = Math.max(jobs[d], profit[i]);
7+
f[d] = Math.max(f[d], profit[i]);
98
}
10-
11-
for (let i = 1, x = 0; i <= wMax; i++) {
12-
jobs[i] = Math.max(jobs[i], jobs[i - 1]);
9+
for (let i = 1; i <= m; ++i) {
10+
f[i] = Math.max(f[i], f[i - 1]);
1311
}
14-
15-
return worker.reduce((acc, w) => acc + jobs[w], 0);
12+
return worker.reduce((acc, w) => acc + f[Math.min(w, m)], 0);
1613
}

0 commit comments

Comments
 (0)