Longest Increasing Subsequence

public class Solution {
           public int lengthOfLIS(int[] nums) {

        if(nums.length==0){
            return 0;
        }
        int[] lens= new int[nums.length];
        lens[0]=1;
        int max=1;
        for(int i=1;i<nums.length;i++){
            for (int j = 0; j < i; j++) {
                if(nums[i]>nums[j] && lens[i]<lens[j]){
                    lens[i]=lens[j];
                }
            }
            lens[i]++;
            max=Math.max(max,lens[i]);
        }
        return max;
    }
}

猜你喜欢

转载自kaqi.iteye.com/blog/2298700