Fichas
Longest Increasing Subsequence
Fichas del conjunto (1)
- 1Input: [10,9,2,5,3,7,101,18] Output: 4 Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4.public int lengthOfLIS(int[] nums) {
int n = nums.length;
int[] lis = new int[n];
for(int i = 0; i< n; i++){
lis[i] = 1;
}
for( int i = 1; i < n; i++){
for( int j = 0; j < i; j++){
if( nums[j] < nums[i] && lis[i] < lis[j]+1){
lis[i] = lis[j] + 1;
}
}
}
int max = 0;
for( int i = 0; i < lis.length; i++){
max = Math.max(max, lis[i]);
}
return max;
}
Información
- Descripción
- Fichas sobre Longest Increasing Subsequence, creado por Suhas S el 28/05/2018.
- Creado por
- Suhas S · may 2018
- Actualizado
- 28 may 2018
- Visitas
- 0
- Valoración