Skip to content

Commit e7e41cd

Browse files
author
zj
committed
62. Unique Paths
1 parent 398ec00 commit e7e41cd

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

code/062. Unique Paths/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# 62. Unique Paths
2+
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
3+
4+
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 the diagram below).
5+
6+
How many possible unique paths are there?
7+
8+
[img](http://leetcode.com/wp-content/uploads/2014/12/robot_maze.png)
9+
10+
Above is a 3 x 7 grid. How many possible unique paths are there?
11+
12+
Note: m and n will be at most 100.

code/062. Unique Paths/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {number} m
3+
* @param {number} n
4+
* @return {number}
5+
*/
6+
//Distribution 89.58%,runtime 96ms
7+
var uniquePaths = function(m, n) {
8+
var list = [];
9+
for(var x = 0; x < m; x++)
10+
list[x] = [];
11+
list[0][0] = 1;
12+
for(x = 0; x < m; x++){
13+
for(var y = 0; y < n; y++){
14+
if(x === 0 || y === 0) list[x][y] = 1;
15+
else list[x][y] = list[x - 1][y] + list[x][y - 1];
16+
}
17+
}
18+
return list[m - 1][n - 1];
19+
};

0 commit comments

Comments
 (0)