Simple Java nLogn


  • 0
    S
    public class Solution {
        public int findContentChildren(int[] g, int[] s) {
            Arrays.sort(g);
            Arrays.sort(s);
            int i = g.length - 1, j = s.length - 1;
            int count = 0;
            while (i >= 0 && j >= 0) {
                while (i >= 0 && g[i] > s[j]) {
                    i--;
                }
                count = i >= 0 ? count + 1 : count;
                i--;
                j--;
            }
            return count;
        }
    }
    

Log in to reply
 

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