Leetcode 62. Unique Paths

版权声明:博客文章都是作者辛苦整理的,转载请注明出处,谢谢! https://blog.csdn.net/Quincuntial/article/details/84897346

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Unique Paths

2. Solution

class Solution {
public:
    int uniquePaths(int m, int n) {
        vector<vector<int>> path(m, vector<int>(n));
        path[0][0] = 1;
        for(int i = 0; i < m; i++) {
            for(int j = 0; j < n; j++) {
                if(i > 0 && j > 0) {
                    path[i][j] = path[i - 1][j] + path[i][j - 1];
                }
                else if(i < 1 && j > 0) {
                    path[i][j] = path[i][j - 1];
                }
                else if(i > 0 && j < 1) {
                    path[i][j] = path[i - 1][j];
                }
            }
        }
        return path[m - 1][n - 1];
    }
};

Reference

  1. https://leetcode.com/problems/unique-paths/description/
阅读更多

扫码向博主提问

SnailTyan

博客专家

非学,无以致疑;非问,无以广识
  • 擅长领域:
  • 深度学习
  • PyTorch
  • OCR
  • Docker
  • Caffe
去开通我的Chat快问

没有更多推荐了,返回首页