Java short O(mn) time, O(n) space


  • 0
    Y
    public int uniquePaths(int m, int n) {
            int[] paths = new int[n];
            Arrays.fill(paths, 1);
            for(int i=0; i<m-1; i++)
                for(int j=1; j<n; j++)
                    paths[j] = paths[j] + paths[j-1];
            return paths[n-1];
        }
    

Log in to reply
 

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