Recursive Top Down DP Java (7 lines)


  • 0
    L
        public int uniquePaths(int m, int n) {
            int[][] map = new int[m][n];
            return uniquePaths(m - 1,n - 1, map);
        }
        
        public int uniquePaths(int m, int n, int[][] map) {
            if (m == 0 || n == 0) return 1;
            if (map[m][n] == 0) map[m][n] = uniquePaths(m -1, n, map) + uniquePaths(m, n - 1, map);
            return map[m][n];
        }
    

Log in to reply
 

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