当前位置:网站首页>【LeetCode】300.最长上升子序列
【LeetCode】300.最长上升子序列
2022-06-12 22:17:00 【LawsonAbs】
1.题目
2.思想
dp题
- 状态:设
dp[i]表示以nums[i]为 结尾得到的最大的上升子序列长度 - 策略:如何得到状态转移公式?
dp[i]会 依赖i前的所有数j,其中 j < i j<i j<i,递推式便是
d p [ i ] = d p [ j ] + 1 , i f n u m [ i ] > n u m [ j ] dp[i] = dp[j] + 1,\ if \ num[i] > num[j] dp[i]=dp[j]+1, if num[i]>num[j]
不断更新取最大就行了
3.代码
class Solution:
def lengthOfLIS(self, nums: List[int]) -> int:
dp = [1] * len(nums) # 自身都是1
# s 表示的是区间长度
for i in range(0,len(nums)):
for j in range(0,i):
if nums[i] > nums[j]:
dp[i] = max(dp[j]+1,dp[i])
res = dp[0]
for i in range(len(nums)):
res = max(res,dp[i])
return res
边栏推荐
- PCB package download website recommendation and detailed usage
- Leetcode Yanghui triangle
- Afraid to write documents? AI plug-in for automatically generating code documents
- February 27th
- Database daily question --- day 10: combine two tables
- 数据库每日一题---第10天:组合两个表
- 关于 安装Qt5.15.2启动QtCreator后“应用程序无法正常启动0xc0000022” 的解决方法
- 生成小程序菊花码(生成菊花码、更换中间logo、更改图片尺寸,加文字)
- The programmer dedicated to promoting VIM has left. Father of vim: I will dedicate version 9.0 to him
- What are thread scheduler and timeslicing?
猜你喜欢

How to perform disaster recovery and recovery for kubernetes cluster? (22)
![[data analysis] data clustering and grouping based on kmeans, including Matlab source code](/img/76/deec6cf60c0d02e99ebc3e21d3b8a4.png)
[data analysis] data clustering and grouping based on kmeans, including Matlab source code

Yyds dry inventory insider news: Series high-frequency interview questions, worth a visit!

JVM foundation > G1 garbage collector

孙老师版本JDBC(2022年6月12日21:34:25)

Ansible playbook and ansible roles (III)
![[probability theory and mathematical statistics] final review: formula summary and simple examples (end)](/img/f5/1c8392aaf87ea323524e94e3f213ed.png)
[probability theory and mathematical statistics] final review: formula summary and simple examples (end)

Xingda easy control modbustcp to profibusdp

Ansible-大总结(六)

Design a MySQL table for message queue to store message data
随机推荐
You can move forward or backward. This function in idea is amazing!
February 27th
Ansible playbook and variable (II)
Unity commonly used 3D mathematical calculation
SQL query list all views in SQL Server 2005 database - SQL query to list all views in an SQL Server 2005 database
Ansible summary (VI)
[sword finger offer] sword finger offer 58 - ii Rotate string left
[QNX hypervisor 2.2 user manual] 4.2 supported build environments
Oracle livelabs experiment: introduction to Oracle Spatial
Qt Quick 3D学习:使用鼠标键盘控制节点位置和方向
The programmer dedicated to promoting VIM has left. Father of vim: I will dedicate version 9.0 to him
JVM foundation > CMS garbage collector
How to specify your webpage's language so Google Chrome doesn't offer to translate it
One article to quickly understand whether there are security risks in your network
[sword finger offer simple] sword finger offer 24 Reverse linked list
June training (day 11) - matrix
【Proteus仿真】简易数码管定时器时钟
Implementation of master-slave replication and master-master replication for MySQL and MariaDB databases
Vagrantbox reinstalling the vboxsf driver
Thread safe level