Day 26 — Unique Paths

class Solution {
public int uniquePaths(int m, int n) {
if(m == 0 || n == 0) return 0;
int[][] grid = new int[m][n];
//fill all cells with 1. This will eventually be updated
for(int[] ar: grid) {
Arrays.fill(ar, 1);
}

for(int i = 1 ; i < m; i++){
for(int j = 1 ; j < n ; j++) {
grid[i][j] = grid[i-1][j] + grid [i][j-1];
}
}
return grid[m-1][n-1];
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store