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

For example,
Given [10, 9, 2, 5, 3, 7, 101, 18],
The longest increasing subsequence is [2, 3, 7, 101], therefore the length is 4. Note that there may be more than one LIS combination, it is only necessary for you to return the length.

Your algorithm should run in O(n2) complexity.

Follow up: Could you improve it to O(n log n) time complexity?

dp解决,注意这里的递增序列不是指连续的递增 ,可以是不连续的, 代码如下:

 class Solution {
public:
int lengthOfLIS(vector<int>& nums) {
if(nums.size() <= ) return nums.size();
vector<int> dp(nums.size(), );
int maxVal = ;
for(int i = ; i < nums.size(); ++i){
dp[i] = ;
for(int j = ; j < i; ++j){
if(nums[j] < nums[i]){
dp[i] = max(dp[i], dp[j]+);
maxVal = max(dp[i], maxVal);
}
}
}
return maxVal;
}
};

最新文章

  1. SVN版本库(访问权限)配置实例笔记
  2. Mysql 连接sleep状态问题解决。
  3. php数组函数,字符串,linux命令
  4. ActiveMQ第五弹:增加ReDelivery功能
  5. [Angular2 Router] Understand the Angular 2 Base href Requirement
  6. AMQ学习笔记 - 06. 可靠消息传送
  7. [JQuery]学习总结
  8. CentOS6安装配置rsh
  9. Unity问答——请问一下动画状态机怎么判断动画是否播完了?
  10. Git应用于Android项目的入门知识:我的理解
  11. Sending HTML Form Data
  12. kettle工具实现报表导出的初步搭建
  13. fopen fclose feof fgets fetl
  14. java.lang.UnsupportedClassVersionError: JVMCFRE003解决方法--jdk 1.6 中switch的参数无法使用String类型
  15. GoldenGate OGG-01032 There Is a Problem in Network Communication Error in Writing to Rmt Remote Trail Rmttrail (Doc ID 1446621.1)
  16. Java之旅_高级教_集合框架
  17. 谈论linux同组多用户操作问题
  18. 【Java】快速排序的非递归实现
  19. android 横竖屏 切换
  20. 微信小程序 - 自定义switch切换(示例)

热门文章

  1. TOSCA自动化测试工具--识别元素唯一性的控件
  2. jQuery判断元素是否显示 是否隐藏
  3. [JavaScript]YYYY-MM-DD格式字符串计算年龄
  4. Scrapy 分布式数据采集方案
  5. Response attachment filename 中文乱码
  6. [BZOJ4003]城池攻占
  7. Redis中RedisTemplate和Redisson管道的使用
  8. mysql参数及解释
  9. 爬虫框架Scrapy之详解
  10. python collections deque