当前位置:网站首页>【LeetCode】300. Longest ascending subsequence
【LeetCode】300. Longest ascending subsequence
2022-06-12 22:22:00 【LawsonAbs】
1. subject
2. thought
dp topic
- state : set up
dp[i]Said tonums[i]by The maximum length of ascending subsequence obtained at the end - Strategy : How to get the state transition formula ?
dp[i]Meeting rely on i All the numbers before j, among j < i j<i j<i, Recursion is
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]
Keep updating to get the maximum
3. Code
class Solution:
def lengthOfLIS(self, nums: List[int]) -> int:
dp = [1] * len(nums) # Itself is 1
# s It represents the interval length
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
边栏推荐
- Ansible foundation and common modules (I)
- C语言:如何给全局变量起一个别名?
- Leetcode Yanghui triangle
- Ansible PlayBook et ansible roles (3)
- 最近公共祖先问题你真的学会了吗?
- [sword finger offer] sword finger offer 35 Replication of complex linked list
- Wechat applet withdrawal function
- China barcode decoder market trend report, technical innovation and market forecast
- Su embedded training day13 - file IO
- Ansible roles project case (IV)
猜你喜欢

Prefix sum and difference

Mysql concat_ws、concat函数使用

flutter系列之:flutter中常用的GridView layout详解

Producer consumer model under multithreading model

JVM foundation - > talk about class loader two parent delegation model

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

微信小程序提现功能
![[image denoising] image denoising based on trilateral filter with matlab code](/img/f2/770a0e2938728e731c18c0a66f7c12.png)
[image denoising] image denoising based on trilateral filter with matlab code

"Oracle database parallel execution" technical white paper reading notes

Ansible PlayBook et ansible roles (3)
随机推荐
四元数简介
[Jianzhi offer] Jianzhi offer 05 Replace spaces
反走样/抗锯齿技术
Su embedded training day13 - file IO
Database daily question --- day 10: combine two tables
[web technology] 1348- talk about several ways to implement watermarking
管线中的坐标变换
How to specify your webpage's language so Google Chrome doesn't offer to translate it
Photoshop:PS如何实现放大图片不模糊
Is it safe to open an account in tonghuashun? How to open an account for securities
The programmer dedicated to promoting VIM has left. Father of vim: I will dedicate version 9.0 to him
[image denoising] image denoising based on trilateral filter with matlab code
Ansible summary (VI)
最近公共祖先问题你真的学会了吗?
Research Report on truffle fungus industry - market status analysis and development prospect forecast
China barcode decoder market trend report, technical innovation and market forecast
【LeetCode】102. 二叉树的层序遍历
web3 原则和去中心化
[simple] 155 Minimum stack
【890. 查找和替换模式】