MCPcopy Create free account
hub / github.com/Hsinha11/Leetcode-solutions / uniquePaths

Method uniquePaths

62-unique-paths/unique-paths.java:4–24  ·  view source on GitHub ↗
(int m, int n)

Source from the content-addressed store, hash-verified

2
3class Solution {
4 public int uniquePaths(int m, int n) {
5 int[][] dp = new int[m][n];
6
7 // First row
8 for (int j = 0; j < n; j++) {
9 dp[0][j] = 1;
10 }
11
12 // First column
13 for (int i = 0; i < m; i++) {
14 dp[i][0] = 1;
15 }
16
17 for (int i = 1; i < m; i++) {
18 for (int j = 1; j < n; j++) {
19 dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
20 }
21 }
22
23 return dp[m - 1][n - 1];
24 }
25}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected