Skip to content

Commit

Permalink
feat: 575.distribute-candies update Python3 implementation (azl397985…
Browse files Browse the repository at this point in the history
  • Loading branch information
ybian19 authored and azl397985856 committed Sep 2, 2019
1 parent 72ab477 commit 35d8ef9
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions problems/575.distribute-candies.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

## 题目地址
https://leetcode.com/problems/distribute-candies/description/

Expand All @@ -11,13 +10,13 @@ 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.
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.
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.
Note:
The length of the given array is in range [2, 10,000], and will be even.
Expand All @@ -43,6 +42,10 @@ The number in given array is in range [-100,000, 100,000].

## 代码

* 语言支持:JS, Python

Javascript Code:

```js
/*
* @lc app=leetcode id=575 lang=javascript
Expand All @@ -59,4 +62,10 @@ var distributeCandies = function(candies) {
};
```

Python Code:

```python
class Solution:
def distributeCandies(self, candies: List[int]) -> int:
return min(len(set(candies)), len(candies) >> 1)
```

0 comments on commit 35d8ef9

Please sign in to comment.