[JAVA] Simple greed check / T : O(N), S : O(1)


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

Log in to reply
 

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