leetCode62. 不同路径

leetCode62. 不同路径

题目思路

代码

cpp 复制代码
class Solution {
public:
    int uniquePaths(int m, int n) {
        // m行n列
        vector<vector<int>> f(m, vector<int> (n));
        for(int i = 0; i < m; i++){
            for(int j = 0; j < n; j++){
                if(!i && !j) f[i][j] = 1;
                else{
                    if(i) f[i][j] += f[i - 1][j];
                    if(j) f[i][j] += f[i][j - 1];
                }
            }
        }

        return f[m - 1][n - 1];
    }
};
相关推荐
2351616 小时前
【LeetCode】146. LRU 缓存
java·后端·算法·leetcode·链表·缓存·职场和发展
tkevinjd19 小时前
反转链表及其应用(力扣2130)
数据结构·leetcode·链表
程序员烧烤20 小时前
【leetcode刷题007】leetcode116、117
算法·leetcode
Swift社区1 天前
LeetCode 395 - 至少有 K 个重复字符的最长子串
算法·leetcode·职场和发展
Espresso Macchiato1 天前
Leetcode 3710. Maximum Partition Factor
leetcode·职场和发展·广度优先遍历·二分法·leetcode hard·leetcode 3710·leetcode双周赛167
巴里巴气1 天前
第15题 三数之和
数据结构·算法·leetcode
西阳未落1 天前
LeetCode——双指针(进阶)
c++·算法·leetcode
熬了夜的程序员1 天前
【LeetCode】69. x 的平方根
开发语言·算法·leetcode·职场和发展·动态规划
Swift社区1 天前
LeetCode 394. 字符串解码(Decode String)
算法·leetcode·职场和发展
tt5555555555551 天前
LeetCode进阶算法题解详解
算法·leetcode·职场和发展