Dp solution, o(n2) time, o(n) space;


  • 0
    1
    int uniquePaths(int m, int n) {
        const int size=n;
        int array[size]={1};
        while(m>0){
            --m;
            for(int i=1;i<n;++i)
                array[i]+=array[i-1];
        }
        return array[n-1];
    }

Log in to reply
 

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