Java DP solution with 1d array


  • 1
    S
    public class Solution {
        public int uniquePaths(int m, int n) {
            int[] table = new int[n];
            Arrays.fill(table, 1);
            for(int i= 1; i<m; i++) {
                for(int j=1; j<n; j++) {
                    table[j] = table[j] + table[j-1];
                }  
            }
            return table[n-1];
        }
    }
    

Log in to reply
 

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