2024/6/1 2928. 给小朋友们分糖果 I
分析
枚举所有可能的方案数即可
代码实现
class Solution {
public:
int distributeCandies(int n, int limit) {
int ans = 0;
for (int a = 0; a <= limit; ++a) {
for (int b = 0; b + a <= n && b <= limit; ++b) {
for (int c = 0; a + b + c <= n && c <= limit; ++c) {
ans += a + b + c == n;
}
}
}
return ans;
}
};
标签:2928,int,每日,2024,合集,LeetCode
From: https://www.cnblogs.com/sleeeeeping/p/18225534