GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Karteikarten

Longest Increasing Subsequence

Suhas S Englisch 1 Karte

Karten in diesem Stapel (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;
    }

Informationen

Beschreibung
Karteikarten am Longest Increasing Subsequence, erstellt von Suhas S am 28/05/2018.
Erstellt von
Suhas S · Mai 2018
Aktualisiert
28 Mai 2018
Aufrufe
0
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck