当前位置:网站首页>【LeetCode】53. Maximum subarray and
【LeetCode】53. Maximum subarray and
2022-06-12 22:22:00 【LawsonAbs】
1. subject
2. thought
dp[i]Said tonums[i]Maximum value obtained at the end- The recursive formula :
dp[i+1] = max(dp[i],0)+ num[i+1]
3. Code
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
dp = [0] * len(nums)
dp[0] = nums[0]
res = dp[0]
for i in range(1,len(nums)):
if dp[i-1]>0:
dp[i] = dp[i-1] + nums[i]
else:
dp[i] = nums[i]
res = max(res,dp[i])
# print(dp)
return res
边栏推荐
- Database daily question --- day 10: combine two tables
- Pat grade A - 1167 Cartesian tree (30 points) (buildtree + level traversal)
- 在同花顺开户证券安全吗,买股票怎么网上开户
- June training (day 10) - bit operation
- Have you really learned the common ancestor problem recently?
- PCB package download website recommendation and detailed usage
- Es6+ new content
- 设计消息队列存储消息数据的 MySQL 表格
- [image denoising] image denoising based on trilateral filter with matlab code
- Prefix sum and difference
猜你喜欢

The interface testing tool apipos3.0 is applicable to process testing and reference parameter variables

Mr. Sun's version of JDBC (21:34:25, June 12, 2022)

设计消息队列存储消息数据的 MySQL 表格

Ansible playbook and variable (II)

最近公共祖先问题你真的学会了吗?

反走样/抗锯齿技术

Ansible foundation and common modules (I)

How to prevent phishing emails? S/mime certificate to help!

QT quick 3D learning: mouse picking up objects

Configuring Dingding notification of SQL audit platform archery
随机推荐
【LeetCode】5. 最长回文子串
JVM foundation - > what is STW?
Audio and video technology development weekly 𞓜 234
Palindrome linked list and linked list intersection problem (intersecting with Xinyi people) do you really know?
[web technology] 1348- talk about several ways to implement watermarking
Unity 常用3D数学计算
[medium] 78 Subset (backtracking shall be supplemented later)
Interpretation of OCP function of oceanbase Community Edition
Several Tsinghua students I know have left
Mysql concat_ws、concat函数使用
[Jianzhi offer] Jianzhi offer 05 Replace spaces
反走样/抗锯齿技术
leetcodeSQL:574. Elected
C#读取word中表格数据
【LeetCode】209. 长度最小的子数组
【Proteus仿真】简易数码管定时器时钟
Producer consumer model under multithreading model
VIM use the lower right 4 keys
Research Report on market supply and demand and strategy of China's digital camera lens industry
JVM foundation > CMS garbage collector