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 c19845f commit 5eeaa46Copy full SHA for 5eeaa46
longest-increasing-subsequence/TonyKim9401.java
@@ -0,0 +1,22 @@
1
+// TC: O(n log n)
2
+// -> nums for loop O(n) + binarySearch O(log n)
3
+// SC: O(n)
4
+// -> ArrayList could have nums all elements
5
+class Solution {
6
+ public int lengthOfLIS(int[] nums) {
7
+ List<Integer> output = new ArrayList<>();
8
+
9
+ for (int num : nums) {
10
+ int start = 0;
11
+ int end = output.size();
12
+ while (start < end) {
13
+ int mid = start + (end - start) / 2;
14
+ if (output.get(mid) < num) start = mid + 1;
15
+ else end = mid;
16
+ }
17
+ if (start == output.size()) output.add(num);
18
+ else output.set(start, num);
19
20
+ return output.size();
21
22
+}
0 commit comments