Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 171e824

Browse files
committed
Add solution #575
1 parent 96a6a65 commit 171e824

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

0575-distribute-candies.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* 575. Distribute Candies
3+
* https://leetcode.com/problems/distribute-candies/
4+
* Difficulty: Easy
5+
*
6+
* Alice has n candies, where the ith candy is of type candyType[i]. Alice noticed that
7+
* she started to gain weight, so she visited a doctor.
8+
*
9+
* The doctor advised Alice to only eat n / 2 of the candies she has (n is always even).
10+
* Alice likes her candies very much, and she wants to eat the maximum number of different
11+
* types of candies while still following the doctor's advice.
12+
*
13+
* Given the integer array candyType of length n, return the maximum number of different
14+
* types of candies she can eat if she only eats n / 2 of them.
15+
*/
16+
17+
/**
18+
* @param {number[]} candyType
19+
* @return {number}
20+
*/
21+
var distributeCandies = function(candyType) {
22+
return Math.min(new Set(candyType).size, candyType.length / 2);
23+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
565|[Array Nesting](./0565-array-nesting.js)|Medium|
223223
566|[Reshape the Matrix](./0566-reshape-the-matrix.js)|Easy|
224224
567|[Permutation in String](./0567-permutation-in-string.js)|Medium|
225+
575|[Distribute Candies](./0575-distribute-candies.js)|Easy|
225226
599|[Minimum Index Sum of Two Lists](./0599-minimum-index-sum-of-two-lists.js)|Easy|
226227
605|[Can Place Flowers](./0605-can-place-flowers.js)|Easy|
227228
606|[Construct String from Binary Tree](./0606-construct-string-from-binary-tree.js)|Easy|

0 commit comments

Comments
 (0)