leetcode455

public class Solution {
    public int FindContentChildren(int[] g, int[] s) {
        var listg = g.OrderBy(x => x).ToList();
            var lists = s.OrderBy(x => x).ToList();

            int i = 0;
            int j = 0;

            int children = 0;

            while (i < listg.Count && j < lists.Count)
            {
                var greed = listg[i];
                var cookie = lists[j];
                if (greed > cookie)
                {
                    j++;
                }
                else
                {
                    //greed<=cookie
                    children++;
                    i++;
                    j++;
                }
            }
            Console.WriteLine(children);
            return children;
    }
}

https://leetcode.com/problems/assign-cookies/#/description

原文地址:https://www.cnblogs.com/asenyang/p/6732351.html