当前位置:网站首页>【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
边栏推荐
- June training (day 11) - matrix
- How to develop programming learning with zero foundation during college
- 大学期间零基础如何开展编程学习
- Economist focuses on WTO MC12: digital economy may become an important issue
- 【LeetCode】33. 搜索旋转排序数组
- [machine learning] learning notes 01- introduction
- 常见渲染管线整理
- Why is pain rating important?
- 四元数简介
- List of open source alternative projects of world famous Cloud Service SaaS companies
猜你喜欢

You can move forward or backward. This function in idea is amazing!

Su embedded training day13 - file IO

Kotlin collaboration process - flow

基于51单片机的酒精检测仪

JVM Basics - > how GC determines that an object can be recycled

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

Ansible playbook和Ansible Roles(三)

Configuring Dingding notification of SQL audit platform archery

反走样/抗锯齿技术

Audio and video technology development weekly 𞓜 234
随机推荐
[data analysis] data clustering and grouping based on kmeans, including Matlab source code
[medium] 78 Subset (backtracking shall be supplemented later)
Su embedded training day13 - file IO
Create a virtual thread using loom - David
Mysql case when then函数使用
[Jianzhi offer] Jianzhi offer 05 Replace spaces
[sword finger offer] sword finger offer 58 - ii Rotate string left
Leetcode Yanghui triangle
JVM Basics - > What are the JVM parameters?
设计消息队列存储消息数据的 MySQL 表格
[probability theory and mathematical statistics] final review: formula summary and simple examples (end)
JVM foundation - what is the process of loading > objects into the JVM, and then clearing them by GC?
孙老师版本JDBC(2022年6月12日21:34:25)
2022-02-28 incluxdb high availability planning
Use group_ Dplyr issues when using group_ by(multiple variables)
Ansible playbook and ansible roles (III)
How to develop programming learning with zero foundation during college
Research Report on water sports shoes industry - market status analysis and development prospect forecast
Database daily question --- day 10: combine two tables
Qt Quick 3D学习:使用鼠标键盘控制节点位置和方向