[LeetCode]Longest Increasing Subsequence

public class Solution {
    public int lengthOfLIS(int[] nums) {
        int length = nums.length;
        List<Integer> record = new ArrayList<Integer>();
        for (int i = length - 1; i >= 0; i--) {
            int count = 0;
            if (record.isEmpty()) {
                record.add(nums[i]);
                continue;
            }
            for (int j = record.size() - 1; j >= 0; j--) {
                if (nums[i] < record.get(j)) {
                    count = j + 1;
                    break;
                }
            }
            if (record.size() > count) {
                record.set(count, Math.max(nums[i], record.get(count)));
            } else {
                record.add(nums[i]);
            }
        }
        return record.size();
    }
}

 

posted @ 2015-12-01 09:30  Weizheng_Love_Coding  阅读(121)  评论(0编辑  收藏  举报