share my java solution!


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

Log in to reply
 

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