Skip to content

Commit

Permalink
Merge pull request #537 from aishwarya-chandra/day9q1
Browse files Browse the repository at this point in the history
day9q1
  • Loading branch information
bh-g authored Jan 24, 2024
2 parents c80949d + 65ee6a2 commit e7c19ec
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Day 9/q1: Longest Increasing Subsequence/aishwarya--J.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
```
Using Binary Search
class Solution {
public int lengthOfLIS(int[] nums) {
int[] tails = new int[nums.length];
int size = 0;
for (int x : nums) {
int i = 0, j = size;
while (i != j) {
int m = (i + j) / 2;
if (tails[m] < x)
i = m + 1;
else
j = m;
}
tails[i] = x;
if (i == size) ++size;
}
return size;
}
}
```

0 comments on commit e7c19ec

Please sign in to comment.