Created
April 28, 2020 16:16
-
-
Save Youngestdev/69fde8e3024ee97b3891920407dd6fc5 to your computer and use it in GitHub Desktop.
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 { | |
| public: | |
| int uniquePaths(int m, int n) { | |
| int dp[n][m]; | |
| dp[0][0] = 1; | |
| if (m == 0 || n == 0) { | |
| return 0; | |
| } | |
| for(int i = 0; i < n; i++) { | |
| dp[i][0] = 1; | |
| } | |
| for (int j = 0; j < m; j++) { | |
| dp[0][j] = 1; | |
| } | |
| for (int i = 1; i < n; i++){ | |
| for (int j = 1; j < m; j++){ | |
| dp[i][j] = dp[i-1][j] + dp[i][j-1]; | |
| } | |
| } | |
| return dp[n-1][m-1]; | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment