forked from SnowScriptWinterOfCode/LeetCode_Q
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request SnowScriptWinterOfCode#528 from aishwarya-chandra/…
…day21q3 day21q3
- Loading branch information
Showing
1 changed file
with
17 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
``` | ||
class Solution { | ||
private int traverse(int i, int j, int[][] memo, int m, int n) { | ||
if (i < 0 || j < 0 || i >= m || j >= n) return 0; | ||
if (i == m-1 && j == n-1) return 1; | ||
if (memo[i][j] != 0) return memo[i][j]; | ||
memo[i][j] = traverse(i+1, j, memo, m, n) + traverse(i, j+1, memo, m, n); | ||
return memo[i][j]; | ||
} | ||
public int uniquePaths(int m, int n) { | ||
var memo = new int[m][n]; | ||
return traverse(0, 0, memo, m, n); | ||
} | ||
} | ||
``` |