File tree 2 files changed +24
-0
lines changed
2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ;
Original file line number Diff line number Diff line change 222
222
565|[ Array Nesting] ( ./0565-array-nesting.js ) |Medium|
223
223
566|[ Reshape the Matrix] ( ./0566-reshape-the-matrix.js ) |Easy|
224
224
567|[ Permutation in String] ( ./0567-permutation-in-string.js ) |Medium|
225
+ 575|[ Distribute Candies] ( ./0575-distribute-candies.js ) |Easy|
225
226
599|[ Minimum Index Sum of Two Lists] ( ./0599-minimum-index-sum-of-two-lists.js ) |Easy|
226
227
605|[ Can Place Flowers] ( ./0605-can-place-flowers.js ) |Easy|
227
228
606|[ Construct String from Binary Tree] ( ./0606-construct-string-from-binary-tree.js ) |Easy|
You can’t perform that action at this time.
0 commit comments