mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-07 09:45:04 +08:00
Formatted with Google Java Formatter
This commit is contained in:
@ -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) {
|
||||
@ -70,8 +69,7 @@ public class LongestIncreasingSubsequence {
|
||||
for (int i = 1; i < size; i++) {
|
||||
int index = binarySearchBetween(arr, lis, a[i]);
|
||||
arr[index] = a[i];
|
||||
if (index > lis)
|
||||
lis++;
|
||||
if (index > lis) lis++;
|
||||
}
|
||||
return lis;
|
||||
}
|
||||
@ -79,19 +77,13 @@ public class LongestIncreasingSubsequence {
|
||||
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;
|
||||
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;
|
||||
if (t[middle] < key) left = middle;
|
||||
else right = middle;
|
||||
}
|
||||
return right;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user