From 65ee6a2dee3aa02b006da9796916083b2926222e Mon Sep 17 00:00:00 2001 From: Aishwarya Chandra <122461230+aishwarya-chandra@users.noreply.github.com> Date: Tue, 23 Jan 2024 21:08:10 +0000 Subject: [PATCH] day9q1 --- .../aishwarya--J.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Day 9/q1: Longest Increasing Subsequence/aishwarya--J.md diff --git a/Day 9/q1: Longest Increasing Subsequence/aishwarya--J.md b/Day 9/q1: Longest Increasing Subsequence/aishwarya--J.md new file mode 100644 index 00000000..9fd576b7 --- /dev/null +++ b/Day 9/q1: Longest Increasing Subsequence/aishwarya--J.md @@ -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; + } +} + +``` \ No newline at end of file