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];
    }
};
相关推荐
青 春 记 忆35 分钟前
LeetCode 226. 翻转二叉树|Python 解法详解
python·算法·leetcode
啊嘞嘞?1 小时前
力扣(回文链表)
算法·leetcode·链表
wabs6662 小时前
关于栈【力扣150.逆波兰表达式求值的思考】
数据结构·c++·算法·leetcode··代码随想录
Navigator_Z11 小时前
LeetCode //C - 1206. Design Skiplist
c语言·算法·leetcode
码行山野赴时序归途11 小时前
三道经典数组题:从暴力到最优的算法思维
c语言·开发语言·数据结构·算法·leetcode
Navigator_Z13 小时前
LeetCode //C - 1209. Remove All Adjacent Duplicates in String II
c语言·算法·leetcode
土司大王16 小时前
LeetCode hot100——合并两个有序链表
算法·leetcode·链表
wabs6661 天前
关于栈【力扣1047. 删除字符串中的所有相邻重复项的思考】
数据结构·c++·算法·leetcode··代码随想录
evans在进步1 天前
LeetCode 53 最大子数组和:一次遍历掌握 Kadane 算法
算法·leetcode·职场和发展
Nil2081 天前
leetcode 230二叉搜索树中第k小的元素
算法·leetcode·职场和发展