当前位置:网站首页>【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
边栏推荐
- 認識的幾比特清華同學都離職了……
- C#读取word中表格数据
- 微信小程序提现功能
- The interface testing tool apipos3.0 is applicable to process testing and reference parameter variables
- [Jianzhi offer] Jianzhi offer 05 Replace spaces
- 【LeetCode】69. x 的平方根
- 【Proteus仿真】简易数码管定时器时钟
- About the solution to "the application cannot start normally 0xc00000022" after qt5.15.2 is installed and qtcreator is started
- 数据库每日一题---第10天:组合两个表
- 2022-02-28 incluxdb high availability planning
猜你喜欢
![[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)

Mr. Sun's version of JDBC (21:34:25, June 12, 2022)
![[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

JVM Basics - > What are the thread shared areas in the JVM

Ansible基础和常用模块(一)

Ansible playbook和Ansible Roles(三)

JVM foundation > G1 garbage collector

SQL query list all views in SQL Server 2005 database - SQL query to list all views in an SQL Server 2005 database

Photoshop:PS如何实现放大图片不模糊

Ansible playbook and variable (II)
随机推荐
ShardingSphere-proxy-5.0.0部署之分表实现(一)
在同花顺开户证券安全吗,买股票怎么网上开户
flutter系列之:flutter中常用的GridView layout详解
认识的几位清华同学都离职了……
四元数简介
Ansible playbook和Ansible Roles(三)
[medium] 78 Subset (backtracking shall be supplemented later)
经济学人聚焦WTO MC12:数字经济或成重要议题
【LeetCode】5. 最长回文子串
USB mechanical keyboard changed to Bluetooth Keyboard
Es6+ new content
Leetcode: the maximum number of building change requests that can be reached (if you see the amount of data, you should be mindless)
Open source background management system suitable for outsourcing projects
How to prevent phishing emails? S/mime certificate to help!
Ansible roles project case (IV)
Photoshop:PS如何实现放大图片不模糊
设计消息队列存储消息数据的 MySQL 表格
Redis optimization
【LeetCode】数组中第K大的元素
【LeetCode】69. x 的平方根