码迷,mamicode.com
首页 > 其他好文 > 详细

[LeetCode]Longest Increasing Subsequence

时间:2015-12-01 09:41:45      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

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

 

[LeetCode]Longest Increasing Subsequence

标签:

原文地址:http://www.cnblogs.com/vision-love-programming/p/5009146.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!