当前位置:网站首页>【LeetCode】53.最大子数组和
【LeetCode】53.最大子数组和
2022-06-12 22:17:00 【LawsonAbs】
1.题目
2.思想
dp[i]表示以nums[i]结尾时获取的最大值- 递推公式:
dp[i+1] = max(dp[i],0)+ num[i+1]
3.代码
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
边栏推荐
- [C language] data type occupation
- 【概率论与数理统计】期末复习抱佛脚:公式总结与简单例题(完结)
- 孙老师版本JDBC(2022年6月12日21:34:25)
- Kotlin collaboration process - flow
- The programmer dedicated to promoting VIM has left. Father of vim: I will dedicate version 9.0 to him
- Vagrantbox reinstalling the vboxsf driver
- Ansible playbook和Ansible Roles(三)
- 3.5 测试类的setup和teardown
- [data analysis] data clustering and grouping based on kmeans, including Matlab source code
- Interpretation of OCP function of oceanbase Community Edition
猜你喜欢

PE installation win10 system

SQL tuning guide notes 15:controlling the use of optimizer statistics

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

Ansible summary (VI)

Ansible playbook and variable (II)

SQL tuning guide notes 17:importing and exporting optimizer statistics

SQL tuning guide notes 10:optimizer statistics concepts

LNMP platform docking redis service

Pat grade A - 1167 Cartesian tree (30 points) (buildtree + level traversal)

PCB package download website recommendation and detailed usage
随机推荐
[simple] 155 Minimum stack
经济学人聚焦WTO MC12:数字经济或成重要议题
Mr. Sun's version of JDBC (21:34:25, June 12, 2022)
Is it safe to open an account in tonghuashun? How to open an account
Have you really learned the common ancestor problem recently?
JVM Basics - > how to troubleshoot JVM problems in your project
PE安装win10系统
孙老师版本JDBC(2022年6月12日21:34:25)
What is the difference between a user thread and a daemon thread?
Create a virtual thread using loom - David
接口测试工具apipost3.0版本对于流程测试和引用参数变量
Preliminary use of jvisualvm
How to specify your webpage's language so Google Chrome doesn't offer to translate it
Ansible summary (VI)
[image denoising] image denoising based on trilateral filter with matlab code
打新债开户安全么,新手该怎么操作?
Unity 常用3D数学计算
JVM foundation > CMS garbage collector
2023届校园招聘正式开启!OceanBase 想和你在这个春天约一场面试
One article to quickly understand whether there are security risks in your network