simple C solution,without extra mem


  • 0
    W
    int* getRow(int rowIndex, int* returnSize) {
        *returnSize=rowIndex+1;
        int *ret=(int *)calloc(*returnSize,sizeof(int));
        int tmp=0,tmp1=0;
        ret[0]=1;
        for(int i=1;i<*returnSize;i++){
        	ret[0]=ret[i]=1;
        	tmp=ret[0];
        	for(int j=1;j<i;j++){
        		tmp1=tmp+ret[j];
        		tmp=ret[j];
        		ret[j]=tmp1;
        	}    	
        }
        return ret;
    }
    

Log in to reply
 

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