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

1. Description

Leetcode 62. 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/

相关文章:

  • 2021-08-02
  • 2021-12-14
  • 2021-09-10
  • 2022-12-23
  • 2021-09-06
  • 2021-11-03
猜你喜欢
  • 2021-06-19
  • 2021-10-24
  • 2021-12-17
  • 2021-07-25
  • 2021-06-29
  • 2021-07-11
  • 2021-08-01
相关资源
相似解决方案