Created
December 24, 2018 00:38
-
-
Save zhangxiaomu01/8040037f69fb9991450d374afbee5ddf to your computer and use it in GitHub Desktop.
This file contains 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) { | |
if(m <=0 || n <= 0) return 0; | |
return UP(m-1, n-1); | |
} | |
int UP(int m, int n){ | |
//move out of boundary, it's invalid, should not be counted as a path | |
if(m < 0 || n <0) return 0; | |
//Robot hits the boundary, we can guarantee to have one way to reach the destination | |
if(m==0 || n==0) return 1; | |
//We calculate the sum of how many panths from two paths | |
return UP(m-1, n) + UP(m, n-1); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment