[LC] 300. Longest Increasing Subsequence
2024-09-30 09:36:33
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 is4
.
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;
}
}
最新文章
- SpringMVC Controller 介绍
- PHP超全局变量
- User Agent跨站攻击
- memcached 基本操作
- TreeSet与TreeMap浅解
- 【Delphi】圆角窗体
- hdu 4111 Alice and Bob 博弈论
- 词汇小助手V3.0发布了——不只是一个查单词的软件
- 【Java基础】继承的一些总结
- oracle 回收站
- 解决mysql不能远程登录的问题
- Notepad++去除代码行号的几种方法
- Statement执行DQL语句(查询操作)
- 測试JSON RPC远程调用(JSONclient)
- easelJS入门、事件、spritesheet
- java IO流、集合类部分小知识点总结
- hexo建立github,gitcafe博客并实时同步的要点
- eclipse 更改默认主题,重写默认滚动条样式(安装DevStyle主题插件)
- DTS(待了解)
- JS防抖与节流函数封装
热门文章
- 计算机utf-8/gbk/utf-16对照表
- empty和is_null以及isset函数在0、”0”、‘空串’、NULL、false、array()的计算值
- Mac中制作USB系统启动盘
- [原]排错实战——使用process explorer替换任务管理器
- Idea创建Spring项目
- CodeForces 995B Suit and Tie(贪心,暴力)
- Linux shell脚本 基础
- mysql 视图 事务 索引
- Django静态文件配置-request方法-ORM简介-字段的增删改查
- framebuffer 知识点