当前位置:网站首页>【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
边栏推荐
- JVM Basics - > how GC determines that an object can be recycled
- Logstash timestamp converted to UNIX nanosecond nano second time
- PCB package download website recommendation and detailed usage
- Have you really learned the common ancestor problem recently?
- How to abstract a problem into a 0-1 knapsack problem in dynamic programming
- One article to quickly understand whether there are security risks in your network
- 孙老师版本JDBC(2022年6月12日21:34:25)
- How to specify your webpage's language so Google Chrome doesn't offer to translate it
- About the solution to "the application cannot start normally 0xc00000022" after qt5.15.2 is installed and qtcreator is started
- RAID disk array
猜你喜欢
![[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)

【图像去噪】基于三边滤波器实现图像去噪附matlab代码

leetcodeSQL:574. Elected

Ansible playbook and variable (II)

Prefix sum and difference

LNMP platform docking redis service

NoSQL - redis configuration and optimization (II) high availability, persistence and performance management

Database daily question --- day 10: combine two tables

Ansible playbook和变量(二)

A puzzle about + =
随机推荐
JVM foundation - > talk about class loader two parent delegation model
[medium] 78 Subset (backtracking shall be supplemented later)
June training (day 11) - matrix
在同花顺开户证券安全吗,证券开户怎么开户流程
Leetcode Yanghui triangle
Ansible-大总结(六)
[QNX hypervisor 2.2 user manual] 4.2 supported build environments
Palindrome linked list and linked list intersection problem (intersecting with Xinyi people) do you really know?
LNMP platform docking redis service
Prefix sum and difference
微信小程序提现功能
[sword finger offer simple] sword finger offer 24 Reverse linked list
logstash时间戳转换为unix 纳秒nano second time
How to prevent phishing emails? S/mime certificate to help!
Step by step evolution of restful API version Frankel
PCB package download website recommendation and detailed usage
Audio and video technology development weekly 𞓜 234
[sword finger offer] sword finger offer 58 - ii Rotate string left
What are thread scheduler and timeslicing?
JVM foundation - what is the process of loading > objects into the JVM, and then clearing them by GC?