File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 54
54
53|[ Maximum Subarray] ( ./0053-maximum-subarray.js ) |Easy|
55
55
54|[ Spiral Matrix] ( ./0054-spiral-matrix.js ) |Medium|
56
56
58|[ Length of Last Word] ( ./0058-length-of-last-word.js ) |Easy|
57
+ 62|[ Unique Paths] ( ./0062-unique-paths.js ) |Medium|
57
58
66|[ Plus One] ( ./0066-plus-one.js ) |Easy|
58
59
67|[ Add Binary] ( ./0067-add-binary.js ) |Easy|
59
60
69|[ Sqrt(x)] ( ./0069-sqrtx.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 62. Unique Paths
3
+ * https://leetcode.com/problems/unique-paths/
4
+ * Difficulty: Medium
5
+ *
6
+ * There is a robot on an m x n grid. The robot is initially located at the top-left
7
+ * corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner
8
+ * (i.e., grid[m - 1][n - 1]). The robot can only move either down or right at any
9
+ * point in time.
10
+ *
11
+ * Given the two integers m and n, return the number of possible unique paths that
12
+ * the robot can take to reach the bottom-right corner.
13
+ */
14
+
15
+ /**
16
+ * @param {number } m
17
+ * @param {number } n
18
+ * @return {number }
19
+ */
20
+ var uniquePaths = function ( m , n ) {
21
+ const row = new Array ( n ) ;
22
+
23
+ for ( let i = 0 ; i < n ; i ++ ) {
24
+ row [ i ] = 1 ;
25
+ }
26
+
27
+ for ( let i = 1 ; i < m ; i ++ ) {
28
+ for ( let j = 1 ; j < n ; j ++ ) {
29
+ row [ j ] += row [ j - 1 ] ;
30
+ }
31
+ }
32
+
33
+ return row [ n - 1 ] ;
34
+ } ;
You can’t perform that action at this time.
0 commit comments