Skip to content

Commit 42e2974

Browse files
committed
https://leetcode.cn/problems/partition-array-into-disjoint-intervals/
1 parent 0130408 commit 42e2974

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Step 2. Add the dependency
4545

4646
<summary>展开查看</summary>
4747

48+
https://leetcode.cn/problems/partition-array-into-disjoint-intervals/
49+
4850
https://leetcode.cn/problems/maximum-profit-in-job-scheduling/
4951

5052
https://leetcode.cn/problems/booking-concert-tickets-in-groups/
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default function partitionDisjoint(nums: number[]): number {
2+
const n = nums.length;
3+
let leftMax = nums[0],
4+
leftPos = 0,
5+
curMax = nums[0];
6+
for (let i = 1; i < n - 1; i++) {
7+
curMax = Math.max(curMax, nums[i]);
8+
if (nums[i] < leftMax) {
9+
leftMax = curMax;
10+
leftPos = i;
11+
}
12+
}
13+
return leftPos + 1;
14+
}

0 commit comments

Comments
 (0)