File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ namespace LeetCode . EasyProblems ;
2
+
3
+ /// <summary>
4
+ /// https://leetcode.com/problems/assign-cookies/
5
+ /// </summary>
6
+ public class AssignCookies
7
+ {
8
+ public int FindContentChildren ( int [ ] greed , int [ ] cookieSize )
9
+ {
10
+ // Sort the greed factors and cookie sizes in ascending order
11
+ Array . Sort ( greed ) ; // O(n log n), where n = greed.Length
12
+ Array . Sort ( cookieSize ) ; // O(m log m), where m = cookieSize.Length
13
+
14
+ int child = 0 ; // Pointer for greed array (children)
15
+ int cookie = 0 ; // Pointer for cookieSize array (cookies)
16
+ int count = 0 ; // Number of content children
17
+
18
+ // Try to satisfy each child with the smallest sufficient cookie
19
+ while ( child < greed . Length && cookie < cookieSize . Length )
20
+ {
21
+ if ( greed [ child ] <= cookieSize [ cookie ] )
22
+ {
23
+ // If the current cookie can satisfy the current child
24
+ count ++ ; // Increment content children count
25
+ child ++ ; // Move to next child
26
+ }
27
+ // Move to next cookie in either case
28
+ cookie ++ ;
29
+ }
30
+ return count ;
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments