最大子数组
来源:互联网 发布:linux sleep 1s 编辑:程序博客网 时间:2024/06/10 18:08
最大字数组
最大字数组,和最小字数组的代码几乎一样。
class Solution {
public:
/*
* @param nums: A list of integers
* @return: A integer indicate the sum of max subarray
*/
int maxSubArray(vector<int> &nums) {
// write your code here
int s=nums[0];
int x=0;
int i;
int l=nums.size();
for(i=0;i<l;i++)
{ x=x+nums[i];
if(x>=s) {s=x;}
if(x<0) {x=0;}
}
return s;
}
};
阅读全文
0 0
- 求最大子数组
- 求最大子数组
- 子数组和最大
- 求最大子数组
- 最大子数组
- 最大子数组和
- 最大子数组和
- 子数组最大和
- 子数组最大乘积
- 最大子数组
- 最大子数组乘积
- 最大子数组和
- 子数组最大和
- 子数组最大和
- 最大子数组二
- 最大连续子数组
- 最大子数组问题
- 最大子数组算法
- 小C语言--词法分析程序
- CodeForces 865D Buy Low Sell High(思维)
- POJ 2358|URAL 1034|Queens in Peaceful Positions
- 第四周项目4 猴子选大王
- Java并发编程 03 Java 线程状态图
- 最大子数组
- big (Trie)
- poj 3494 Largest Submatrix of All 1’s
- Spring Aop(五)——给Advice传递参数
- Git使用教程
- 51nod 1052 最大M子段和 (区间dp)
- Qt常用类 QFont
- #1 Judging Cars
- 【DBSDFZOJ 4445】棋盘(组合数学-错排公式+高精度)