GoConqr has a new look! Let us know what you think.

Flashcards

Longest Increasing Subsequence

Suhas S English 1 card

Cards in this deck (1)

  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;
    }

Information

Description
Flashcards on Longest Increasing Subsequence, created by Suhas S on 28/05/2018.
Created by
Suhas S · May 2018
Updated
May 28, 2018
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?