leetcode 腾讯精选-62

题目:
https://leetcode-cn.com/problems/unique-paths/submissions/
代码:
class Solution {
public:
int uniquePaths(int m, int n) {

    if(m <= 0 || n <=0)
    {
        return 0;            
    }
    
    if(m == 1 || n == 1)
        return 1;
    if(m == 2)
    {
        return n;
    }
    
    if(n == 2)
    {
        return m;
    }
           
    int res ;
    
    res = uniquePaths(m-2,n) + 2*uniquePaths(m - 1, n - 1) + uniquePaths(m , n - 2);
    
    return res;
}

};
结果
leetcode 腾讯精选-62_第1张图片

你可能感兴趣的:(c++)