Simple Java Solution 19 ms


  • 0
    G

    ...
    public int findContentChildren(int[] greedFactor, int[] cookieSize) {

    	int retValue=0;
    	int actualRet = 0;
        //case 1 cookie size is 0
    	if(cookieSize==null || cookieSize.length==0){
    		return retValue;
    	}
    	
    	//Sort the greedFactor
    	Arrays.sort(greedFactor);
    	Arrays.sort(cookieSize);
    	int i=0;
    	for(int k=0;k<cookieSize.length;k++) {
    	if(i<greedFactor.length && greedFactor[i]<=cookieSize[k]) {
    			cookieSize[k] = cookieSize[k]-greedFactor[i];
    			actualRet++;
    			i++;
    		}
    	}
    	return actualRet;
    

    }
    ...


Log in to reply
 

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