Java solution (very easy to understand)


  • 0
    L
    class Solution {
        public int uniquePaths(int m, int n) {
            if(m==0 || n==0)
            {
                return 0;
            }
                
            else {
                int[][] path = new int[m][n];
                for(int i=0;i<m;i++)
                {
                    for(int j=0;j<n;j++)
                    {
                        path[0][j]=1;
                        path[i][0]=1;
                        if(i>=1 && j>=1)
                        {
                            path[i][j]=path[i-1][j]+path[i][j-1];
                        }
                    }
                }
                return path[m-1][n-1];
            }
    }
    }
    

Log in to reply
 

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