File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 238
238
292|[ Nim Game] ( ./0292-nim-game.js ) |Easy|
239
239
295|[ Find Median from Data Stream] ( ./0295-find-median-from-data-stream.js ) |Hard|
240
240
297|[ Serialize and Deserialize Binary Tree] ( ./0297-serialize-and-deserialize-binary-tree.js ) |Hard|
241
+ 300|[ Longest Increasing Subsequence] ( ./0300-longest-increasing-subsequence.js ) |Medium|
241
242
303|[ Range Sum Query - Immutable] ( ./0303-range-sum-query-immutable.js ) |Easy|
242
243
306|[ Additive Number] ( ./0306-additive-number.js ) |Medium|
243
244
309|[ Best Time to Buy and Sell Stock with Cooldown] ( ./0309-best-time-to-buy-and-sell-stock-with-cooldown.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 300. Longest Increasing Subsequence
3
+ * https://leetcode.com/problems/longest-increasing-subsequence/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given an integer array nums, return the length of the longest strictly increasing subsequence.
7
+ */
8
+
9
+ /**
10
+ * @param {number[] } nums
11
+ * @return {number }
12
+ */
13
+ var lengthOfLIS = function ( nums ) {
14
+ if ( ! nums . length ) return 0 ;
15
+
16
+ const dp = new Array ( nums . length ) . fill ( 1 ) ;
17
+ for ( let i = 1 ; i < nums . length ; i ++ ) {
18
+ for ( let j = 0 ; j < i ; j ++ ) {
19
+ if ( nums [ i ] > nums [ j ] ) {
20
+ dp [ i ] = Math . max ( dp [ i ] , dp [ j ] + 1 ) ;
21
+ }
22
+ }
23
+ }
24
+
25
+ return Math . max ( ...dp ) ;
26
+ } ;
You can’t perform that action at this time.
0 commit comments