Skip to content

Commit 35afb4d

Browse files
committed
904. 水果成篮 (二刷)
1 parent 74912d6 commit 35afb4d

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

algorithms/fruit-into-baskets.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
2+
* 904. 水果成篮
23
* @param {number[]} fruits
34
* @return {number}
45
*/
@@ -11,6 +12,7 @@ var totalFruit = function (fruits) {
1112

1213
for (let right = 0; right < fruits.length; right++) {
1314
const curr = fruits[right];
15+
// 存储每个水果种类出现的次数
1416
map.set(curr, (map.get(curr) || 0) + 1);
1517

1618
while (map.size > 2) {
@@ -22,6 +24,7 @@ var totalFruit = function (fruits) {
2224
}
2325
left++;
2426
}
27+
// 更新最大数目
2528
maxLen = Math.max(maxLen, right - left + 1);
2629
}
2730

0 commit comments

Comments
 (0)