Simple java solution


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

Log in to reply
 

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