https://leetcode.com/problems/distribute-candies-among-children-i/
Distribute Candies Among Children I - LeetCode
Can you solve this real interview question? Distribute Candies Among Children I - You are given two positive integers n and limit. Return the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.
leetcode.com
1
2
3
4
5
6
7
8
9
10
|
class Solution:
def distributeCandies(self, n: int, limit: int) -> int:
answer = 0
for i in range(limit+1):
for j in range(limit+1):
for k in range(limit+1):
if i+j+k == n:
answer += 1
return answer
|
cs |
브루트포스 말고... 경우의수 같은걸로 할수도있을거같아요
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 2828. Check if a String Is an Acronym of Words (0) | 2023.12.28 |
---|---|
백준 14913 등차수열에서 항 번호 찾기 (0) | 2023.12.28 |
leetcode CodeTestcaseTestcaseTest Result2942. Find Words Containing Character (0) | 2023.12.27 |
leetcode 2951. Find the Peaks (0) | 2023.12.27 |
leetcode 2956. Find Common Elements Between Two Arrays (0) | 2023.12.27 |
댓글