当前位置:网站首页>LeetCode#53. Maximum subarray sum
LeetCode#53. Maximum subarray sum
2022-07-06 15:21:00 【Rufeng ZHHH】
subject :
Give you an array of integers nums , Please find a continuous subarray with the largest sum ( A subarray contains at least one element ), Return to its maximum and .
Subarray Is a continuous part of the array .
Example 1:
Input :nums = [-2,1,-3,4,-1,2,1,-5,4]
Output :6
explain : Continuous subarray [4,-1,2,1] And the biggest , by 6 .
Example 2:
Input :nums = [1]
Output :1
Example 3:
Input :nums = [5,4,-1,7,8]
Output :23
This problem is still a dynamic programming problem , We can get before n The sum of the elements , Then calculate once , Finally get the maximum value .
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
dp=[0]*len(nums)
dp[0]=nums[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]
return max(dp)
边栏推荐
- Video scrolling subtitle addition, easy to make with this technique
- Servlet
- Build your own application based on Google's open source tensorflow object detection API video object recognition system (I)
- 软件测试面试要问的性能测试术语你知道吗?
- Install and run tensorflow object detection API video object recognition system of Google open source
- HackTheBox-Emdee five for life
- Threads et pools de threads
- The minimum sum of the last four digits of the split digit of leetcode simple problem
- Pedestrian re identification (Reid) - data set description market-1501
- What are the software testing methods? Show you something different
猜你喜欢

ucore lab5用户进程管理 实验报告

Want to change jobs? Do you know the seven skills you need to master in the interview software test

软件测试有哪些常用的SQL语句?

MySQL数据库(四)事务和函数

In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.

How to write the bug report of software test?

The minimum sum of the last four digits of the split digit of leetcode simple problem

CSAPP homework answers chapter 789
What to do when programmers don't modify bugs? I teach you
遇到程序员不修改bug时怎么办?我教你
随机推荐
[HCIA continuous update] working principle of static route and default route
Investment should be calm
安全测试入门介绍
UCORE lab1 system software startup process experimental report
The maximum number of words in the sentence of leetcode simple question
Nest and merge new videos, and preset new video titles
The wechat red envelope cover designed by the object is free! 16888
Global and Chinese markets of cobalt 2022-2028: Research Report on technology, participants, trends, market size and share
基于485总线的评分系统双机实验报告
Pedestrian re identification (Reid) - data set description market-1501
Global and Chinese markets for GaN on diamond semiconductor substrates 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL数据库(一)
Stc-b learning board buzzer plays music
Mysql database (I)
51 lines of code, self-made TX to MySQL software!
pytest
Mysql的事务
Global and Chinese markets of Iam security services 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of portable and handheld TVs 2022-2028: Research Report on technology, participants, trends, market size and share
CSAPP家庭作业答案7 8 9章