53. Maximum Subarray
来源:互联网 发布:浪漫主义文学 知乎 编辑:程序博客网 时间:2024/06/06 17:34
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.
For example, given the array [-2,1,-3,4,-1,2,1,-5,4]
,
the contiguous subarray [4,-1,2,1]
has the largest sum = 6
.
经常出的题,也属于动态规划。
#把注释去掉可以求得区间。class Solution: def maxSubArray(self, nums): """ :type nums: List[int] :rtype: int """ s,ms=0,nums[0] #begin=end=b=e=0 for i in range(len(nums)): s+=nums[i] if s>ms: ms=s """ begin=b e=i end=e """ if s<0: s=0 """ b=i+1 e=i+1 """ #print(nums[begin,end+1]) return ms
阅读全文
0 0
- [LeetCode]53.Maximum Subarray
- LeetCode --- 53. Maximum Subarray
- 53.Maximum Subarray
- [Leetcode] 53. Maximum Subarray
- [leetcode] 53.Maximum Subarray
- 53.Maximum Subarray
- 53. Maximum Subarray
- 【leetcode】53. Maximum Subarray
- [leetcode] 53.Maximum Subarray
- 【leetcode】53. Maximum Subarray
- 53. Maximum Subarray
- LeetCode 53. Maximum Subarray
- 53. Maximum Subarray
- [LeetCode]53. Maximum Subarray
- 53. Maximum Subarray LeetCode
- 53. Maximum Subarray
- [LeetCode]53. Maximum Subarray
- 53. Maximum Subarray
- Zxing实现二维码生成和解析,可带logo
- Java内部类
- Self Dividing Numbers
- 关于Android源码中|= (m & STATIC_VALUE) !=0 的理解
- windows nginx 静态文件缓存配置
- 53. Maximum Subarray
- 如果有人问你爬虫抓取技术的门道,请叫他来看这篇文章
- Gradle初次使用
- jvm内存分配技术
- C语言经典项目之二——扫雷
- 1自己常用Linux常用命令
- S5PV210的启动过程详解(一)
- 【洛谷2982】[Usaco2010 Feb]慢下来Slowdown(dfs序+线段树)
- [BZOJ3669][NOI2014]魔法森林(LCT)