Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 323c8e8

Browse files
Create 3638-maximum-balanced-shipments.js
1 parent f899102 commit 323c8e8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎3638-maximum-balanced-shipments.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @param {number[]} weight
3+
* @return {number}
4+
*/
5+
var maxBalancedShipments = function (weight) {
6+
const n = weight.length
7+
let res = 0
8+
let i = 0
9+
10+
while (i < n) {
11+
let maxWeight = weight[i]
12+
let j = i
13+
14+
while (j < n) {
15+
maxWeight = Math.max(maxWeight, weight[j])
16+
17+
if (weight[j] < maxWeight) {
18+
res++
19+
break
20+
}
21+
j++
22+
}
23+
24+
i = j === i ? i + 1 : j + 1
25+
}
26+
27+
return res
28+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /