File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 363
363
452|[ Minimum Number of Arrows to Burst Balloons] ( ./0452-minimum-number-of-arrows-to-burst-balloons.js ) |Medium|
364
364
453|[ Minimum Moves to Equal Array Elements] ( ./0453-minimum-moves-to-equal-array-elements.js ) |Medium|
365
365
454|[ 4Sum II] ( ./0454-4sum-ii.js ) |Medium|
366
+ 455|[ Assign Cookies] ( ./0455-assign-cookies.js ) |Easy|
366
367
456|[ 132 Pattern] ( ./0456-132-pattern.js ) |Medium|
367
368
459|[ Repeated Substring Pattern] ( ./0459-repeated-substring-pattern.js ) |Easy|
368
369
461|[ Hamming Distance] ( ./0461-hamming-distance.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 455. Assign Cookies
3
+ * https://leetcode.com/problems/assign-cookies/
4
+ * Difficulty: Easy
5
+ *
6
+ * Assume you are an awesome parent and want to give your children some cookies. But, you
7
+ * should give each child at most one cookie.
8
+ *
9
+ * Each child i has a greed factor g[i], which is the minimum size of a cookie that the
10
+ * child will be content with; and each cookie j has a size s[j]. If s[j] >= g[i], we can
11
+ * assign the cookie j to the child i, and the child i will be content. Your goal is to
12
+ * maximize the number of your content children and output the maximum number.
13
+ */
14
+
15
+ /**
16
+ * @param {number[] } g
17
+ * @param {number[] } s
18
+ * @return {number }
19
+ */
20
+ var findContentChildren = function ( g , s ) {
21
+ g . sort ( ( a , b ) => a - b ) ;
22
+ s . sort ( ( a , b ) => a - b ) ;
23
+
24
+ let result = 0 ;
25
+ for ( let j = 0 ; result < g . length && j < s . length ; j ++ ) {
26
+ if ( s [ j ] >= g [ result ] ) {
27
+ result ++ ;
28
+ }
29
+ }
30
+
31
+ return result ;
32
+ } ;
You can’t perform that action at this time.
0 commit comments