2 pointer loop from back to front


  • 0
    	    public int findContentChildren(int[] g, int[] s) {
    	    	Arrays.sort(g);
    	    	Arrays.sort(s);
    	        int p2 = s.length-1;
    	        for(int p1 = g.length-1;p1>=0&&p2>=0;p1--){
    	        	if(s[p2] >= g[p1])p2--;
    	        }
    	        return s.length-1-p2;
    	    }
    

Log in to reply
 

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