My Simple Java Solution


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

Log in to reply
 

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