From 00e2eadae256fe8cf8c7a5ce2737d45d019bf129 Mon Sep 17 00:00:00 2001 From: Aishwarya Chandra <122461230+aishwarya-chandra@users.noreply.github.com> Date: Tue, 23 Jan 2024 20:10:27 +0000 Subject: [PATCH] day21q3 --- Day-21/q3: Unique Paths/aishwarya--J.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Day-21/q3: Unique Paths/aishwarya--J.md diff --git a/Day-21/q3: Unique Paths/aishwarya--J.md b/Day-21/q3: Unique Paths/aishwarya--J.md new file mode 100644 index 00000000..f721bbd9 --- /dev/null +++ b/Day-21/q3: Unique Paths/aishwarya--J.md @@ -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); + } +} +``` \ No newline at end of file