Unique Path using DP (c#)


  • 0
    S
    public int UniquePaths(int m, int n) {
             var dp = new int[m,n];
    
                for (int i = m - 1; i >= 0; i--)
                {
                    for (int j = n - 1; j >= 0; j--)
                    {
                        if (i == m - 1 || j == n - 1)
                        {
                            dp[i, j] = 1;
                        }
                        else
                        {
                            dp[i, j] = dp[i + 1, j] + dp[i, j + 1];
                        }
                    }
                }
    
                return dp[0, 0];
        }
    

Log in to reply
 

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