LeetCode Longest Increasing Subsequence DP

原创 2015年11月17日 23:13:18

思路:

方法一:DP。

时间复杂度O(N^2),空间复杂度O(N)。

java code :

public class Solution {
    public int lengthOfLIS(int[] nums) {
        if(nums == null || nums.length == 0) return 0;
        int[] dp = new int[nums.length];
        Arrays.fill(dp, 1);
        int ans = 1;
        for(int i = 0; i < nums.length; ++i) {
            for(int j = 0; j < i; ++j) {
                if(nums[j] < nums[i]) {
                    dp[i] = Integer.max(dp[i], dp[j] + 1);
                }
            }
            ans = dp[i] > ans ? dp[i] : ans;
        }
        return ans;
    }
}

相关文章推荐

LeetCode Peeking Iterator 迭代器

思路:实现迭代器的peek功能,它会返回next()返回的那个值,但是不会前进。向前缓存一个值。java code:// Java Iterator interface reference: // h...
  • yeruby
  • yeruby
  • 2015年11月17日 09:14
  • 199

大数据平台架构技术选型与场景运用

导读:本文将大数据的工作角色分为三种类型,包括业务相关、数据科学相关和数据工程。大数据平台偏向于工程方面,大数据平台一般包括数据源、数据采集、数据存储、数据分析等方面。 讲师从数据来源、数据源结构、...

(Leetcode)Longest Increasing Subsequence——dp,bisearch

300. Longest Increasing Subsequence 题目 Given an unsorted array of integers, find the length of lon...

DP (7) -- Ones and Zeroes, Longest Increasing Subsequence, Perfect Squares

Ones and Zeroes,Longest Increasing Subsequence,Guess Number Higher or Lower II
  • dwt0317
  • dwt0317
  • 2017年01月11日 14:55
  • 99

[DP]Longest Increasing Subsequence

The longest Increasing Subsequence (LIS) problem is to find the length of the longest subsequence of...

(SPOJ - ELIS )Easy Longest Increasing Subsequence(DP)

Time limit1948 msMemory limit1572864 kBCode length Limit50000 BGiven a list of numbers A output the ...

LeetCode Longest Increasing Subsequence

题目: Given an unsorted array of integers, find the length of longest increasing subsequence. ...

leetcode 300. Longest Increasing Subsequence

Given an unsorted array of integers, find the length of longest increasing subsequence. For examp...

LeetCode 题解(Week6):300. Longest Increasing Subsequence

原题目Given an unsorted array of integers, find the length of longest increasing subsequence.For exampl...

300. Longest Increasing Subsequence/DP

题目描述 代码实现题目描述Given an unsorted array of integers, find the length of longest increasing subsequence....
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:LeetCode Longest Increasing Subsequence DP
举报原因:
原因补充:

(最多只允许输入30个字)