最长递增子序列长度

public int findMaxSubLen(int[] arr){

        if (arr == null){
            return 0;
        }

        int[] longest = new int[arr.length];

        for (int i = 0; i < longest.length; i++){
            longest[i] = 1;
        }

        for (int i = 0; i < arr.length; i++){
            for (int j = 0; j < i; j++){
                if (arr[j] < arr[i] && longest[i] < longest[j] + 1){
                    longest[i] = longest[j] + 1;
                }
            }
        }

        int max = longest[0];
        for (int i = 0; i < longest.length; i++){
            if (longest[i] > max){
                max = longest[i];
            }
        }

        return max;
}

 

你可能感兴趣的:(算法)