给定一个无序的整数数组,找到其中最长上升子序列的长度。

示例:

输入: [10,9,2,5,3,7,101,18] 输出: 4 解释: 最长的上升子序列是 [2,3,7,101],它的长度是 4。

说明:

  • 可能会有多种最长上升子序列的组合,你只需要输出对应的长度即可。
  • 你算法的时间复杂度应该为 O(n2) 。
class Solution {
public:
int lengthOfLIS(vector<int>& nums)
{
int len = nums.size();
if (len == 0)
return 0;
vector<int> dp(len , 1);
for (int i = 0; i < len; i++)
{
for (int j = 0; j < i; j++)
{
if (nums[i] > nums[j])
{
dp[i] = max(dp[j] + 1, dp[i]);
}
}
}
int MAX = 1;
for (int i = 0; i < len; i++)
{
MAX = max(MAX, dp[i]);
}
return MAX;
}
};

Leetcode300. Longest Increasing Subsequence最长上升子序列的更多相关文章

  1. leetcode300. Longest Increasing Subsequence 最长递增子序列 、674. Longest Continuous Increasing Subsequence

    Longest Increasing Subsequence 最长递增子序列 子序列不是数组中连续的数. dp表达的意思是以i结尾的最长子序列,而不是前i个数字的最长子序列. 初始化是dp所有的都为1 ...

  2. [LintCode] Longest Increasing Subsequence 最长递增子序列

    Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...

  3. LeetCode 300. Longest Increasing Subsequence最长上升子序列 (C++/Java)

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

  4. [LeetCode] Longest Increasing Subsequence 最长递增子序列

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

  5. 673. Number of Longest Increasing Subsequence最长递增子序列的数量

    [抄题]: Given an unsorted array of integers, find the number of longest increasing subsequence. Exampl ...

  6. [LeetCode] 300. Longest Increasing Subsequence 最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Inp ...

  7. [leetcode]300. Longest Increasing Subsequence最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Inp ...

  8. 300 Longest Increasing Subsequence 最长上升子序列

    给出一个无序的整形数组,找到最长上升子序列的长度.例如,给出 [10, 9, 2, 5, 3, 7, 101, 18],最长的上升子序列是 [2, 3, 7, 101],因此它的长度是4.因为可能会有 ...

  9. poj 2533 Longest Ordered Subsequence 最长递增子序列

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098562.html 题目链接:poj 2533 Longest Ordered Subse ...

随机推荐

  1. git 去除本地所有没有保存的修改

    git 去除本地所有没有保存的修改,参考How do I revert all local changes in Git managed project to previous state? 知道运行 ...

  2. iptbales无法正常重启

    新主机iptables无法启动关闭和重启 一般是由于没有配文件导致 解决办法 直接touch /etc/sysconfig/iptables 然后就可以正常启动. 备注:一般存在于centos6系列中

  3. Python 正整数相加其余忽略

    从键盘上输入若干数值,对其中的正整数求和,非正整数(负整数,实数或其他符号)忽略,这个过程一直到输入“#”结束. i = 0while True: m = input("请输入一个数:&qu ...

  4. 校园商铺-2项目设计和框架搭建-10验证controller

    1.新建package:com.csj2018.o2o.web.superadmin 2.建立AreaController.java package com.csj2018.o2o.web.super ...

  5. 树形dp——cf1092F

    被傻逼题降智了.. 就是第一次dfs 时 求一次size,一次deep数组 然后第二次dfs时直接求最大值 先把结点1的值求出来, u->v过程中,v子树的所有结点深度-1,v外的所有结点深度+ ...

  6. 有道云笔记新功能发现——有道云笔记剪报,完美解决不开会员保存csdn博客到本地的问题。

    怎么用 方法一:谷歌插件 方法二:http://note.youdao.com/web-clipper-chrome.html 添加到书签 功能: 能够把网页浏览的内容保存到有道云笔记 解决了自己的难 ...

  7. Quartz 定时任务配置(spring中)

    <!-- Quartz -->    <bean name="task" class="com.geostar.geosmarter.nodemanag ...

  8. 接着上回,导包正确之后,出现javabean.Friend cannot be cast to java.util.List,的错误。找了很久。以为是User user0作为参数,改成了String username还是错误,看了看listFriend.jsp没有错误,我想会不会是包多了,导致类型复杂。最后发现包少了一个:

    import org.apache.commons.dbutils.handlers.BeanListHandler;这个包,BeanListHandler让我发现List<Friend> ...

  9. 17.获取代理ip

    import redis import telnetlib import urllib.request from bs4 import BeautifulSoup r = redis.Redis(ho ...

  10. 靖烜小哥哥之mybatis总结

    MyBatis是一个半自动映射的框架.“半自动”是相对于Hibernate全表映射而言的,MyBatis需要手动匹配提供POJO.SQL和映射关系,而Hibernate只需提供POJO和映射关系即可. ...