Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int uniquePaths(int m, int n) {
- if(m== 0 || n == 0){
- return 1;
- }
- if(m < 0 || n < 0){
- return 0;
- }
- int[][] cache = new int[m][n];
- for(int i = 0; i<m; i++){
- for(int j = 0; j<n; j++){
- if(i == 0 || j ==0){
- cache[i][j]= 1;
- }else{
- cache[i][j] = cache[i-1][j] + cache[i][j-1];
- }
- }
- }
- return cache[m-1][n-1];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement