Share my code with c 1ms


  • 0
    D
    int uniquePaths(int m, int n) {
         int **a = malloc(sizeof(int *) * m);
         for(int i = 0;i<m;i++){
             a[i] = malloc(sizeof(int) *n);
         }
         for(int i = 0;i<m;i++){
              for(int j = 0;j<n;j++){
    
                   if(i==0 || j==0 ) a[i][j]=1;
                   else a[i][j]=a[i-1][j]+a[i][j-1];
              }
         }
        return a[m-1][n-1];
    

    }


  • 0
    E

    memory leak?
    may no impact to the system, but it is not a good practice i guess


Log in to reply
 

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