Java dp solution


  • 0
    J

    public class Solution {

    public int uniquePaths(int m, int n) {
        int min = Math.min(m,n);
        int max = Math.max(m,n);
        int[] dp = new int[min];
        dp[0] = 1;
        for (int i = 1; i< m + n-1; i++) {
            for (int j = min-1;j> 0; j--) {
                dp[j] += dp[j-1];
            }
        }
        return dp[min-1];
    }
    

    }


Log in to reply
 

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