aboutsummaryrefslogtreecommitdiff
path: root/unique_paths.cpp
blob: 053a92beea5ffc392aae3a08f9d67d39198a865c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "leetcode.h"

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

int main() {
  Solution obj;
  cout << obj.uniquePaths(3, 7);
}