Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4e184cd

Browse files
github-actionsgithub-actions
github-actions
authored and
github-actions
committed
Formatted with Google Java Formatter
1 parent4e70451 commit4e184cd

File tree

1 file changed

+28
-36
lines changed

1 file changed

+28
-36
lines changed

‎DynamicProgramming/LongestIncreasingSubsequence.java‎

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public static void main(String[] args) {
1717
System.out.println(LIS(arr));
1818
System.out.println(findLISLen(arr));
1919
sc.close();
20-
2120
}
2221

2322
privatestaticintupperBound(int[]ar,intl,intr,intkey) {
@@ -58,40 +57,33 @@ private static int LIS(int[] array) {
5857

5958
returnlength;
6059
}
61-
62-
/** @author Alon Firestein (https://github.com/alonfirestein) */
63-
64-
// A function for finding the length of the LIS algorithm in O(nlogn) complexity.
65-
publicstaticintfindLISLen(inta[]) {
66-
intsize =a.length;
67-
intarr[] =newint[size];
68-
arr[0] =a[0];
69-
intlis =1;
70-
for (inti =1;i <size;i++) {
71-
intindex =binarySearchBetween(arr,lis,a[i]);
72-
arr[index] =a[i];
73-
if (index >lis)
74-
lis++;
75-
}
76-
returnlis;
77-
}
60+
61+
/** @author Alon Firestein (https://github.com/alonfirestein) */
62+
63+
// A function for finding the length of the LIS algorithm in O(nlogn) complexity.
64+
publicstaticintfindLISLen(inta[]) {
65+
intsize =a.length;
66+
intarr[] =newint[size];
67+
arr[0] =a[0];
68+
intlis =1;
69+
for (inti =1;i <size;i++) {
70+
intindex =binarySearchBetween(arr,lis,a[i]);
71+
arr[index] =a[i];
72+
if (index >lis)lis++;
73+
}
74+
returnlis;
75+
}
7876
// O(logn)
79-
privatestaticintbinarySearchBetween(int[]t,intend,intkey) {
80-
intleft =0;
81-
intright =end;
82-
if (key <t[0])
83-
return0;
84-
if (key >t[end])
85-
returnend +1;
86-
while (left <right -1) {
87-
intmiddle = (left +right) /2;
88-
if (t[middle] <key)
89-
left =middle;
90-
else
91-
right =middle;
92-
}
93-
returnright;
94-
}
95-
96-
77+
privatestaticintbinarySearchBetween(int[]t,intend,intkey) {
78+
intleft =0;
79+
intright =end;
80+
if (key <t[0])return0;
81+
if (key >t[end])returnend +1;
82+
while (left <right -1) {
83+
intmiddle = (left +right) /2;
84+
if (t[middle] <key)left =middle;
85+
elseright =middle;
86+
}
87+
returnright;
88+
}
9789
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp