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

Example:

Input: [10,9,2,5,3,7,101,18]
Output: 4
Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4.

Note:

  • 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?

Time: O(N^2) 
class Solution {
public int lengthOfLIS(int[] nums) {
if (nums == null || nums.length == 0) {
return 0;
}
int[] arr = new int[nums.length];
int res = 0;
for (int i = 0; i < nums.length; i++) {
arr[i] = 1;
for (int j = 0; j < i; j++) {
if (nums[j] < nums[i]) {
// note which one + 1
arr[i] = Math.max(arr[i], arr[j] + 1);
}
}
res = Math.max(res, arr[i]);
}
return res;
}
}

最新文章

  1. SpringMVC Controller 介绍
  2. PHP超全局变量
  3. User Agent跨站攻击
  4. memcached 基本操作
  5. TreeSet与TreeMap浅解
  6. 【Delphi】圆角窗体
  7. hdu 4111 Alice and Bob 博弈论
  8. 词汇小助手V3.0发布了——不只是一个查单词的软件
  9. 【Java基础】继承的一些总结
  10. oracle 回收站
  11. 解决mysql不能远程登录的问题
  12. Notepad++去除代码行号的几种方法
  13. Statement执行DQL语句(查询操作)
  14. 測试JSON RPC远程调用(JSONclient)
  15. easelJS入门、事件、spritesheet
  16. java IO流、集合类部分小知识点总结
  17. hexo建立github,gitcafe博客并实时同步的要点
  18. eclipse 更改默认主题,重写默认滚动条样式(安装DevStyle主题插件)
  19. DTS(待了解)
  20. JS防抖与节流函数封装

热门文章

  1. 计算机utf-8/gbk/utf-16对照表
  2. empty和is_null以及isset函数在0、”0”、‘空串’、NULL、false、array()的计算值
  3. Mac中制作USB系统启动盘
  4. [原]排错实战——使用process explorer替换任务管理器
  5. Idea创建Spring项目
  6. CodeForces 995B Suit and Tie(贪心,暴力)
  7. Linux shell脚本 基础
  8. mysql 视图 事务 索引
  9. Django静态文件配置-request方法-ORM简介-字段的增删改查
  10. framebuffer 知识点