leetcode 455. biscuits points (java simple greed)

The array is sorted, traversing, if sufficient to meet the child gi ++, but no matter how si has been a plus.

class Solution {
    public int findContentChildren(int[] g, int[] s) {
        Arrays.sort(g);
        Arrays.sort(s);
        int gi=0,si=0;
        while(gi<g.length&&si<s.length){
            if(g[gi]<=s[si])
                gi++;
            si++;
        }
        return gi;
    }
}

 

Guess you like

Origin www.cnblogs.com/y1040511302/p/11470000.html