Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Runtime: 0 ms, faster than 100.00% of Java online submissions for Unique Paths.
- Memory Usage: 33.1 MB, less than 5.10% of Java online submissions for Unique Paths.
- */
- class Solution {
- public int uniquePaths(int m, int n) {
- if (m < 1 || n < 1) return 0;
- int[][] p = new int[m][n];
- for(int j=0; j<n; ++j){
- p[0][j] = 1;
- }
- for(int i=1; i<m; ++i){
- p[i][0] = 1;
- for(int j=1; j<n; ++j){
- p[i][j] = p[i-1][j]+p[i][j-1];
- }
- }
- return p[m-1][n-1];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement