Skip to content

Commit 35d8ef9

Browse files
ybian19azl397985856
authored andcommitted
feat: 575.distribute-candies update Python3 implementation (azl397985856#157)
1 parent 72ab477 commit 35d8ef9

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

problems/575.distribute-candies.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
## 题目地址
32
https://leetcode.com/problems/distribute-candies/description/
43

@@ -11,13 +10,13 @@ Input: candies = [1,1,2,2,3,3]
1110
Output: 3
1211
Explanation:
1312
There 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.
1615
Example 2:
1716
Input: candies = [1,1,2,3]
1817
Output: 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.
2120
Note:
2221
2322
The 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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy