We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3f2b2ec commit 93a584fCopy full SHA for 93a584f
longest-increasing-subsequence/gwbaik9717.js
@@ -0,0 +1,21 @@
1
+// n: len(nums)
2
+// Time complexity: O(n^2)
3
+// Space complexity: O(n)
4
+
5
+/**
6
+ * @param {number[]} nums
7
+ * @return {number}
8
+ */
9
+var lengthOfLIS = function (nums) {
10
+ const dp = Array.from({ length: nums.length }, () => 1);
11
12
+ for (let i = 1; i < nums.length; i++) {
13
+ for (let j = 0; j < i; j++) {
14
+ if (nums[j] < nums[i]) {
15
+ dp[i] = Math.max(dp[i], dp[j] + 1);
16
+ }
17
18
19
20
+ return Math.max(...dp);
21
+};
0 commit comments