Skip to content

Commit 0b5d0ed

Browse files
committed
Add solution #300
1 parent 38f70f0 commit 0b5d0ed

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@
238238
292|[Nim Game](./0292-nim-game.js)|Easy|
239239
295|[Find Median from Data Stream](./0295-find-median-from-data-stream.js)|Hard|
240240
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|
241242
303|[Range Sum Query - Immutable](./0303-range-sum-query-immutable.js)|Easy|
242243
306|[Additive Number](./0306-additive-number.js)|Medium|
243244
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 numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
};

0 commit comments

Comments
 (0)