4line 0ms Java solution only use 1D array

  • 0
    public int uniquePaths(int m, int n) {
        int[] path = new int[n];
        path[0] = 1;
        for (int i=0; i<m; i++) for (int j=1; j<n; j++) path[j] += path[j-1];
        return path[n-1];

Log in to reply

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