Skip to content

Commit cd184df

Browse files
authored
Create LIS.java
1 parent ac963d9 commit cd184df

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Dynamic Programming/LIS.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
class LIS
3+
{
4+
static int liss(int a[],int n)
5+
{
6+
int lis[n];
7+
int i,j,max = 0;
8+
9+
for ( i = 0; i < n; i++ )
10+
lis[i] = 1;
11+
12+
for ( i = 1; i < n; i++ )
13+
for ( j = 0; j < i; j++ )
14+
if ( a[i] > a[j] && lis[i] < lis[j] + 1)
15+
lis[i] = lis[j] + 1;
16+
17+
for ( i = 0; i < n; i++ )
18+
if ( max < lis[i] )
19+
max = lis[i];
20+
21+
return max;
22+
}
23+
24+
public static void main(String args[])
25+
{
26+
int arr[] = { 0,10,20,59,4,1,26,8};
27+
int n = arr.length;
28+
System.out.println("Length of lis is " + liss( arr, n ) + "\n" );
29+
}
30+
}

0 commit comments

Comments
 (0)