0 ms Simple C Solution


  • 1
    A
    int** generate(int numRows, int** columnSizes, int* returnSize) {
    	int i, j;
    	int** result;
    	*returnSize = numRows;
    	*columnSizes = (int *) malloc(sizeof(int) * numRows);
    	result = (int **) malloc(sizeof(int*) * numRows);
    	for(i=0; i<numRows; i++) {
    		*(*columnSizes+i) = i+1;
    		*(result+i) = (int*) malloc(sizeof(int)* (i+1));
    		for(j=0; j<=i; j++) {
    			if(j==0 || j==i) {
    				*(*(result+i) + j) = 1;
    			}
    			else {
    				*(*(result+i) + j) = *(*(result+i-1) + j-1) + *(*(result+i-1) + j);
    			}
    		}
    	}
    	return result;
    }

Log in to reply
 

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