File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 70
70
116|[ Populating Next Right Pointers in Each Node] ( ./0116-populating-next-right-pointers-in-each-node.js ) |Medium|
71
71
118|[ Pascal's Triangle] ( ./0118-pascals-triangle.js ) |Easy|
72
72
119|[ Pascal's Triangle II] ( ./0119-pascals-triangle-ii.js ) |Easy|
73
+ 120|[ Triangle] ( ./0120-triangle.js ) |Medium|
73
74
121|[ Best Time to Buy and Sell Stock] ( ./0121-best-time-to-buy-and-sell-stock.js ) |Easy|
74
75
128|[ Longest Consecutive Sequence] ( ./0128-longest-consecutive-sequence.js ) |Medium|
75
76
133|[ Clone Graph] ( ./0133-clone-graph.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 120. Triangle
3
+ * https://leetcode.com/problems/triangle/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given a triangle array, return the minimum path sum from top to bottom.
7
+ *
8
+ * For each step, you may move to an adjacent number of the row below. More
9
+ * formally, if you are on index i on the current row, you may move to either
10
+ * index i or index i + 1 on the next row.
11
+ */
12
+
13
+ /**
14
+ * @param {number[][] } triangle
15
+ * @return {number }
16
+ */
17
+ var minimumTotal = function ( triangle ) {
18
+ for ( let i = triangle . length - 2 ; i > - 1 ; i -- ) {
19
+ for ( let j = 0 ; j < triangle [ i ] . length ; j ++ ) {
20
+ triangle [ i ] [ j ] += Math . min ( triangle [ i + 1 ] [ j ] , triangle [ i + 1 ] [ j + 1 ] ) ;
21
+ }
22
+ }
23
+
24
+ return triangle [ 0 ] [ 0 ] ;
25
+ } ;
You can’t perform that action at this time.
0 commit comments