Recursive Java Solution


  • 0
    A

    '''
    public class Solution {
    public int uniquePaths(int m, int n) {
    if(m==0 || n ==0) return 0;
    int memo[][] = new int[m][n];
    return paths(m-1, n-1,memo);
    }

    private int paths(int row, int col, int[][] memo){
        if(row<0 || col<0)return 0;
        if(row==0 || col==0) return 1;
        if(memo[row][col]==0)
            memo[row][col] = paths(row-1, col, memo) + paths(row, col-1, memo);
        
       return memo[row][col];
    }
    

    }


Log in to reply
 

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