From 4e184cd95f45003bebabb372262d4ff1d1140aba Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 24 Mar 2021 16:51:59 +0000 Subject: [PATCH] Formatted with Google Java Formatter --- .../LongestIncreasingSubsequence.java | 64 ++++++++----------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/DynamicProgramming/LongestIncreasingSubsequence.java b/DynamicProgramming/LongestIncreasingSubsequence.java index 28f54afdc..90fa08347 100644 --- a/DynamicProgramming/LongestIncreasingSubsequence.java +++ b/DynamicProgramming/LongestIncreasingSubsequence.java @@ -17,7 +17,6 @@ public class LongestIncreasingSubsequence { System.out.println(LIS(arr)); System.out.println(findLISLen(arr)); sc.close(); - } private static int upperBound(int[] ar, int l, int r, int key) { @@ -58,40 +57,33 @@ public class LongestIncreasingSubsequence { return length; } - - /** @author Alon Firestein (https://github.com/alonfirestein) */ - - // A function for finding the length of the LIS algorithm in O(nlogn) complexity. - public static int findLISLen(int a[]) { - int size = a.length; - int arr[] = new int[size]; - arr[0] = a[0]; - int lis = 1; - for (int i = 1; i < size; i++) { - int index = binarySearchBetween(arr, lis, a[i]); - arr[index] = a[i]; - if (index > lis) - lis++; - } - return lis; - } + + /** @author Alon Firestein (https://github.com/alonfirestein) */ + + // A function for finding the length of the LIS algorithm in O(nlogn) complexity. + public static int findLISLen(int a[]) { + int size = a.length; + int arr[] = new int[size]; + arr[0] = a[0]; + int lis = 1; + for (int i = 1; i < size; i++) { + int index = binarySearchBetween(arr, lis, a[i]); + arr[index] = a[i]; + if (index > lis) lis++; + } + return lis; + } // O(logn) - private static int binarySearchBetween(int[] t, int end, int key) { - int left = 0; - int right = end; - if (key < t[0]) - return 0; - if (key > t[end]) - return end + 1; - while (left < right - 1) { - int middle = (left + right) / 2; - if (t[middle] < key) - left = middle; - else - right = middle; - } - return right; - } - - + private static int binarySearchBetween(int[] t, int end, int key) { + int left = 0; + int right = end; + if (key < t[0]) return 0; + if (key > t[end]) return end + 1; + while (left < right - 1) { + int middle = (left + right) / 2; + if (t[middle] < key) left = middle; + else right = middle; + } + return right; + } }