mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-13 02:38:37 +08:00
14 lines
250 B
Go
14 lines
250 B
Go
package main
|
|
|
|
func distributeCandies(n int, limit int) int64 {
|
|
var res int64 = 0
|
|
for i := 0; i <= min(n, limit); i++ {
|
|
last := n - i
|
|
if last > 2*limit {
|
|
continue
|
|
}
|
|
res += int64(min(last, limit) - max(0, last-limit) + 1)
|
|
}
|
|
return res
|
|
}
|