본문 바로가기
python-algorithm

leetcode 2928. Distribute Candies Among Children I

by 무적김두칠 2023. 12. 27.

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+== n:
                        answer += 1
        return answer
        
cs

브루트포스 말고... 경우의수 같은걸로 할수도있을거같아요

반응형

댓글