-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path575. Distribute Candies.py
50 lines (35 loc) · 1.33 KB
/
575. Distribute Candies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# You have n candies, the ith candy is of type candies[i].
# You want to distribute the candies equally between a sister and a brother so that each of them gets n / 2 candies (n is even). The sister loves to collect different types of candies, so you want to give her the maximum number of different types of candies.
# Return the maximum number of different types of candies you can give to the sister.
# Example 1:
# Input: candies = [1,1,2,2,3,3]
# Output: 3
# Explanation:
# There are three different kinds of candies (1, 2 and 3), and two candies for each kind.
# Optimal distribution: The sister has candies [1,2,3] and the brother has candies [1,2,3], too.
# The sister has three different kinds of candies.
# Example 2:
# Input: candies = [1,1,2,3]
# Output: 2
# Explanation: For example, the sister has candies [2,3] and the brother has candies [1,1].
# The sister has two different kinds of candies, the brother has only one kind of candies.
# Example 3:
# Input: candies = [1,1]
# Output: 1
# Example 4:
# Input: candies = [1,11]
# Output: 1
# Example 5:
# Input: candies = [2,2]
# Output: 1
# Constraints:
# n == candies.length
# 2 <= n <= 10^4
# n is even.
# -10^5 <= candies[i] <= 10^5
def distributeCandies(candies):
ans=0
for x in set(candies):
if ans<len(candies)/2:
ans = ans+1
return ans