LintCode之41 最大子数组
来源:互联网 发布:网络凶杀2视频 编辑:程序博客网 时间:2024/05/22 15:26
题目来源:最大子数组
题目描述:
给定一个整数数组,找到一个具有最大和的子数组,返回其最大和。
样例:
给出数组[−2,2,−3,4,−1,2,1,−5,3],符合要求的子数组为[4,−1,2,1],其最大和为6
Java代码:
public int maxSubArray(int[] nums) { // write your code int start=0,end=0,mixsum=nums[0],nowsum=0; while (end<nums.length) { if(nowsum<=0) { nowsum=nums[end]; end++; start=end; }else { nowsum+=nums[end]; end++; } if(nowsum>mixsum) mixsum=nowsum; } return mixsum; }
阅读全文
0 0
- LintCode之41 最大子数组
- LintCode 41 最大子数组
- [Lintcode] #41 最大子数组
- LintCode: 最大子数组
- lintcode ----最大子数组
- lintcode,最大子数组
- 【LintCode】最大子数组
- Lintcode最大子数组
- LintCode 最大子数组
- lintcode最大子数组
- Lintcode:最大子数组
- 【lintcode】最大子数组
- LintCode-剑指Offer-(41)最大子数组
- [LintCode 41] 最大子数组之和(Python)
- LintCode 第41题 最大子数组
- LintCode-最大子数组差
- LintCode-最大子数组 III
- LintCode--最大子数组差
- switch和if else的效问题
- Spring MVC环境搭建、一键式配置方法(注解)以及参数传递
- Bootstrap(十)
- SVM中对函数边距(functional margin) = 1 的思考
- 第2章开箱使用
- LintCode之41 最大子数组
- Java char(字符)和String(字符串)
- Linux命令集锦
- 一个Angular的开发脚手架
- 程序与CPU(PO学校 计算机科学 笔记整理)
- phpexcel 导出格式,字体调整
- hdu 6219
- 带你了解真正的String类的intern()方法
- [BZOJ1717]-[Usaco2006 Dec]Milk Patterns-后缀数组Height模板题