Assign Cookies - Java solution using Greedy


  • 0
    D
    public class Solution {
        public int findContentChildren(int[] g, int[] s) {
            int i = 0,j = 0;
            
            Arrays.sort(g);
            Arrays.sort(s);
            
            while( i < g.length && j < s.length ) {
                if( s[j] >= g[i] )  i++;
                j++;
            }
            
            return i;
        }
    }
    

    Runtime: O(n lg n)


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.