1-
21## 题目地址
32https://leetcode.com/problems/distribute-candies/description/
43
@@ -11,13 +10,13 @@ Input: candies = [1,1,2,2,3,3]
1110Output: 3
1211Explanation:
1312There are three different kinds of candies (1, 2 and 3), and two candies for each kind.
14- Optimal distribution: The sister has candies [1,2,3] and the brother has candies [1,2,3], too.
15- The sister has three different kinds of candies.
13+ Optimal distribution: The sister has candies [1,2,3] and the brother has candies [1,2,3], too.
14+ The sister has three different kinds of candies.
1615Example 2:
1716Input: candies = [1,1,2,3]
1817Output: 2
19- Explanation: For example, the sister has candies [2,3] and the brother has candies [1,1].
20- The sister has two different kinds of candies, the brother has only one kind of candies.
18+ Explanation: For example, the sister has candies [2,3] and the brother has candies [1,1].
19+ The sister has two different kinds of candies, the brother has only one kind of candies.
2120Note:
2221
2322The length of the given array is in range [2, 10,000], and will be even.
@@ -43,6 +42,10 @@ The number in given array is in range [-100,000, 100,000].
4342
4443## 代码
4544
45+ * 语言支持:JS, Python
46+
47+ Javascript Code:
48+
4649``` js
4750/*
4851 * @lc app=leetcode id=575 lang=javascript
@@ -59,4 +62,10 @@ var distributeCandies = function(candies) {
5962};
6063```
6164
65+ Python Code:
6266
67+ ``` python
68+ class Solution :
69+ def distributeCandies (self , candies : List[int ]) -> int :
70+ return min (len (set (candies)), len (candies) >> 1 )
71+ ```
0 commit comments