I'm a new DP learner. Here is my C code.please gice some advice.


  • 0
    1
    int integerBreak(int n) {
       int *pro=(int *)malloc((n+1)*sizeof(int)),i,j;
       for(i=0;i<n+1;i++) pro[i]=i;
       if(n==2) return 1;
       if(n==3) return 2;
       for(i=2;i<n+1;i++)
          for(j=1;j<i;j++){
              if(pro[i]<pro[i-j]*j)
              pro[i]=pro[i-j]*j;
        }
        return pro[n];
    }

Log in to reply
 

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