当前位置:网站首页>[hero planet July training leetcode problem solving daily] dynamic planning on the 28th
[hero planet July training leetcode problem solving daily] dynamic planning on the 28th
2022-07-28 21:55:00 【Seven water Shuliang】
[ Hero planet July training LeetCode Problem solving daily ] The first 28 Japan Dynamic programming
daily
- Today's topic is the largest sub paragraph and , Also known as the largest subarray , classical kadane Algorithm , It is a common algorithm in the field of graphics .
- meanwhile , This is also my entry question , Enjoy the beauty of Algorithm . Start with this question , I find my brain is not enough , With routines, you can kill seconds !
- This problem was first solved by Brown University Ulf Grenander Professor Yu 1977 in , At first, he wanted to show a simple maximum likelihood estimation model in digital images . Soon after, Carnegie Mellon University Jay Kadane A linear algorithm for this problem is proposed .
subject
One 、 53. Maximum subarray and
link : 53. Maximum subarray and
1. Title Description

2. Thought analysis
- The classic is to find the sum of the largest subsegments , Definition dp[i] For i Is the maximum sum of the ending subparagraphs .
- obviously , If dp[i-1] non-negative , It can be accumulated ,dp[i]=a[i]+dp[i-1];
- otherwise , Give up the previous paragraph , Restart the segment ,dp[i] = a[i].
- Last , We find that state transition is only related to the upper layer , Therefore, space can be optimized , Realization O(1) Complexity .
3. Code implementation
class Solution:
# def maxSubArray(self, nums: List[int]) -> int:
# n = len(nums)
# dp = [0] * n
# dp[0] = nums[0]
# for i in range(1,n):
# if dp[i-1] <= 0:
# dp[i] = nums[i]
# else:
# dp[i] = nums[i] + dp[i-1]
# return max(dp)
def maxSubArray(self, nums: List[int]) -> int:
n = len(nums)
dp = nums[0]
ans = dp
for a in nums[1:]:
dp = a if dp <= 0 else dp + a
if ans < dp :
ans = dp
return ans
边栏推荐
- HCIA综合实验(以华为eNSP为例)
- Adventures of little mouse: behind the scenes gags of moss 2
- 开放式耳机哪个音质好、公认音质好的气传导耳机推荐
- Cy3/Cy5/Cy5.5/Cy7荧光标记抗体/蛋白试剂盒(10~100mg标记量)
- How Oracle exports data (how Oracle backs up databases)
- Week 6 Linear Models for Classification (Part B)
- 如何优雅的设计工作流引擎(荣耀典藏版)
- fluke dtx-1800测试精度有必要进行原厂校准吗?
- 世界肝炎日 | 基层也能享受三甲资源,智慧医疗系统如何解决“看病难”?
- HCIA comprehensive experiment (take Huawei ENSP as an example)
猜你喜欢

Is it necessary to calibrate the fluke dtx-1800 test accuracy?

Meta opens the project aria pilot dataset and will develop real-time 3D maps in the future

蚂蚁集团境外站点 Seata 实践与探索

使用Mock技术帮助提升测试效率的小tips,你知道几个?

网格数据生成函数meshgrid

Professional Committee of agricultural water and soil engineering of China Association of Agricultural Engineering - 12th session - Notes

Divide and conquer, upload large files in pieces

软考 --- 数据库(3)数据操作

基于对象的实时空间音频渲染丨Dev for Dev 专栏

Which brand is the best and most cost-effective open headset
随机推荐
数据库读写分离目的是做什么[通俗易懂]
磷脂偶联抗体/蛋白试剂盒的存储与步骤
Divide and conquer, upload large files in pieces
Leetcode 19. delete the penultimate node of the linked list [knowledge points: speed pointer, recursion, stack]
openEuler Embedded SIG | 分布式软总线
With the help of domestic chip manufacturers, the shipment of white brand TWS headphones has reached 600million in 2020
How Oracle exports data (how Oracle backs up databases)
HCIA综合实验(以华为eNSP为例)
这种动态规划你见过吗——状态机动态规划之股票问题(下)
Bully is filed for bankruptcy! The company has become a "Lao Lai", and the legal person is restricted from high consumption
[brother hero July training] day 28: dynamic planning
First week of internship diary
作价11.5亿元,1206件设备注入合资公司!SK海力士抢食大陆晶圆代工市场!
小霸王被申请破产!公司成“老赖” ,法人被限制高消费
1162. Map analysis - non recursive method
搞事摸鱼一天有一天
小程序开发需要什么技术
LeetCode链表问题——面试题02.07.链表相交(一题一文学会链表)
Cross domain transfer learning of professional skill word extraction in Chinese recruitment documents
融合LSTM与逻辑回归的中文专利关键词抽取