Movatterモバイル変換


[0]ホーム

URL:


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

Commitb051614

Browse files
committed
Add solution #2929
1 parent6fac895 commitb051614

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,7 @@
20232023
2900|[Longest Unequal Adjacent Groups Subsequence I](./solutions/2900-longest-unequal-adjacent-groups-subsequence-i.js)|Easy|
20242024
2901|[Longest Unequal Adjacent Groups Subsequence II](./solutions/2901-longest-unequal-adjacent-groups-subsequence-ii.js)|Medium|
20252025
2918|[Minimum Equal Sum of Two Arrays After Replacing Zeros](./solutions/2918-minimum-equal-sum-of-two-arrays-after-replacing-zeros.js)|Medium|
2026+
2929|[Distribute Candies Among Children II](./solutions/2929-distribute-candies-among-children-ii.js)|Medium|
20262027
2942|[Find Words Containing Character](./solutions/2942-find-words-containing-character.js)|Easy|
20272028
2948|[Make Lexicographically Smallest Array by Swapping Elements](./solutions/2948-make-lexicographically-smallest-array-by-swapping-elements.js)|Medium|
20282029
2962|[Count Subarrays Where Max Element Appears at Least K Times](./solutions/2962-count-subarrays-where-max-element-appears-at-least-k-times.js)|Medium|
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* 2929. Distribute Candies Among Children II
3+
* https://leetcode.com/problems/distribute-candies-among-children-ii/
4+
* Difficulty: Medium
5+
*
6+
* You are given two positive integers n and limit.
7+
*
8+
* Return the total number of ways to distribute n candies among 3 children such that no child
9+
* gets more than limit candies.
10+
*/
11+
12+
/**
13+
*@param {number} n
14+
*@param {number} limit
15+
*@return {number}
16+
*/
17+
vardistributeCandies=function(n,limit){
18+
constminCandies=Math.max(0,n-2*limit);
19+
constmaxCandies=Math.min(n,limit);
20+
letresult=0;
21+
22+
for(leti=minCandies;i<=maxCandies;i++){
23+
constremaining=n-i;
24+
constminSecond=Math.max(0,remaining-limit);
25+
constmaxSecond=Math.min(remaining,limit);
26+
result+=maxSecond-minSecond+1;
27+
}
28+
29+
returnresult;
30+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp