Skip to content

Commit 8ccaa29

Browse files
committed
Add leetcode problem 2929
1 parent a9db57f commit 8ccaa29

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

leetcode/src/02929_distribute_candies_among_children_ii/__init__.py

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def distributeCandies(self, n: int, limit: int) -> int:
3+
acc = 0
4+
[
5+
acc := acc + max(min(limit, n - i) - max(0, n - i - limit) + 1, 0)
6+
for i in range(min(n, limit) + 1)
7+
]
8+
return acc
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import unittest
2+
from .solution import Solution
3+
4+
5+
class TestTwoSum(unittest.TestCase):
6+
def test_distributeCandies(self):
7+
s = Solution()
8+
self.assertEqual(s.distributeCandies(5, 2), 3)
9+
self.assertEqual(s.distributeCandies(3, 3), 10)
10+
11+
12+
if __name__ == "__main__":
13+
unittest.main()

0 commit comments

Comments
 (0)