my dp solution just use O(n) space,not O(m*n)


  • 2
    L
      public int uniquePaths(int m, int n) {
        int[]dp = new int[n];
        for(int i = 0; i < m; i++)
          for(int j = 0; j < n; j++){
              if(i == 0 || j == 0){
                  dp[j] = 1;
              }else{
                  dp[j] = dp[j] + dp[j-1];
              }
          }
          return dp[n-1];
        
    }

Log in to reply
 

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