Accepted java solution


  • 0
    V

    public class Solution {

    public int uniquePaths(int m, int n) {  
        m = m-1;  
        n = n-1;  
        if(m + n == 0){  
            return 1;  
        }
        
        else if(m != 0 && n == 0){
            return 1;
        }
        
         else if(m == 0 && n != 0){
            return 1;
        }else{
        
        int[][] paths = new int[m+1][n+1];
        paths[0][0] = 0;
        
        for(int i = 1; i <= m; i++){
            paths[i][0] = 1;
        }
        
        for(int j = 1; j <= n; j++){
            paths[0][j] = 1;
        }
        
        for(int a = 1; a <= m; a++){
            for(int b = 1; b <= n; b++){
                paths[a][b] = paths[a-1][b] + paths[a][b-1];
            }
        }
      
        
        return paths[m][n];
        }
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.