leetcode---maximum-subarray---贪心
来源:互联网 发布:淘宝姜峰手机可信吗 编辑:程序博客网 时间:2024/06/03 15:37
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.
click to show more practice.
More practice:
If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.
class Solution {public: int maxSubArray(int A[], int n) { int ans = INT_MIN, sum = 0; for(int i=0; i<n; i++) { sum = max(A[i], sum + A[i]); ans = max(ans, sum); } return ans; }};
阅读全文
0 0
- leetcode---maximum-subarray---贪心
- LeetCode-53-Maximum Subarray 贪心
- maximum-subarray Java 贪心
- Leetcode 53. Maximum Subarray 贪心或动态规划
- 【LeetCode】Maximum Subarray 和 Maximum Product Subarray
- LeetCode: Maximum Subarray
- LeetCode Maximum Subarray
- [Leetcode] Maximum Subarray
- LeetCode: Maximum Subarray
- leetcode 25: Maximum Subarray
- [LeetCode] Maximum Subarray
- [Leetcode] Maximum Subarray
- [LeetCode]Maximum Subarray
- [leetcode]Maximum Subarray
- LeetCode-Maximum Subarray
- [leetcode] Maximum Subarray
- LeetCode 45: Maximum Subarray
- LeetCode - Maximum Subarray
- linux 卸载 mysql
- Java静态变量 静态代码块 主函数 成员变量 构造代码块 构造函数的执行顺序
- 产品练习
- SQL Injection
- opencv-python(11):形态学转换
- leetcode---maximum-subarray---贪心
- MVC简介
- 台灣愛迪達 奧運Adidas Ultra Boost
- Hdu 5512 Meeting (建图技巧 + 最短路)
- Python 多进程,进程加锁(RLock),进程执行乱序(进程同步)
- 基于VS2013的wxWidgets 3.1.0环境配置
- java 静态初始化块中,方法中不可以定义静态变量(重要)
- 爱的一种解释
- 第五周 项目2