Skip to content

Instantly share code, notes, and snippets.

@soltrinox
Created December 18, 2014 15:49
Show Gist options
  • Save soltrinox/1e44327ea503f5649236 to your computer and use it in GitHub Desktop.
Save soltrinox/1e44327ea503f5649236 to your computer and use it in GitHub Desktop.
Longest Increasing Subsequence
public static int increasingSubsequence(int[]seq){
int[]L=new int[seq.length];
L[0]=1;
for(int i=1;i<L.length;i++){
int maxn=0;
for(int j=0;j<i;j++){
if(seq[j]<seq[i]&&L[j]>maxn){
maxn=L[j];
}
}
L[i]=maxn+1;
}
int maxi=0;
for(int i=0;i<L.length;i++){
if(L[i]>maxi){
maxi=L[i];
}
}
return(maxi);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment