当前位置:网站首页>【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
边栏推荐
- Producer consumer model under multithreading model
- Modstartcms modular station building system v3.3.0 component function upgrade, event triggering enhancement
- Unity commonly used 3D mathematical calculation
- Ansible playbook and variable (II)
- JVM foundation > GC generation: minorgc majorgc fullgc mixed GC
- Is there any risk in opening a securities account? How to open an account safely?
- Market trend report, technical innovation and market forecast of Chinese stump crusher
- Kotlin collaboration process - flow
- USB mechanical keyboard changed to Bluetooth Keyboard
- Mysql concat_ws、concat函数使用
猜你喜欢

Implementation of master-slave replication and master-master replication for MySQL and MariaDB databases

Audio and video technology development weekly 𞓜 234

【数据分析】基于 kmeans实现数据聚类分组含Matlab源码

Qt Quick 3D学习:鼠标拾取物体

QT quick 3D learning: mouse picking up objects

Kotlin collaboration process - flow

Ansible summary (VI)

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

Preliminary use of jvisualvm

RAID disk array
随机推荐
管线中的坐标变换
Su embedded training day13 - file IO
Open source background management system suitable for outsourcing projects
[proteus simulation] simple digital tube timer clock
Is there any risk in opening a securities account? How to open an account safely?
JVM foundation - what is the process of loading > objects into the JVM, and then clearing them by GC?
【LeetCode】209. 长度最小的子数组
C#读取word中表格数据
C语言:如何给全局变量起一个别名?
PCB package download website recommendation and detailed usage
Afraid to write documents? AI plug-in for automatically generating code documents
Wechat applet withdrawal function
Is it safe to open an account in tonghuashun? How to open an account
China's elastic belt market trend report, technical dynamic innovation and market forecast
Kotlin collaboration process - flow
[Jianzhi offer] Jianzhi offer 09 Implementing queues with two stacks
How to develop programming learning with zero foundation during college
JVM foundation > G1 garbage collector
[sword finger offer] sword finger offer 58 - ii Rotate string left
认识的几位清华同学都离职了……