Created
December 4, 2018 12:50
-
-
Save qiaoxu123/81e42efcea0c9291ce4f2e66122419db to your computer and use it in GitHub Desktop.
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//使用动态规划解答 | |
class Solution { | |
int uniquePaths(int m, int n) { | |
if (m > n) return uniquePaths(n, m); | |
vector<int> cur(m, 1); | |
for (int j = 1; j < n; j++) | |
for (int i = 1; i < m; i++) | |
cur[i] += cur[i - 1]; | |
return cur[m - 1]; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment