Skip to content

Commit 061cf43

Browse files
committed
Time: 0 ms (100%), Space: 41.1 MB (32.35%) - LeetHub
1 parent f141138 commit 061cf43

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public long distributeCandies(int n, int limit) {
3+
return combCount(n)
4+
- 3 * combCount(n - (limit + 1))
5+
+ 3 * combCount(n - 2 * (limit + 1))
6+
- combCount(n - 3 * (limit + 1));
7+
}
8+
9+
private long combCount(long sum) {
10+
if (sum < 0) return 0;
11+
return (sum + 2) * (sum + 1) / 2;
12+
}
13+
}

0 commit comments

Comments
 (0)