Maximum Subarray with Sum/ Multiply
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
.
1 public class Solution { 2 public int maxSubArray(int[] A) { 3 if(A.length<=0) return 0; 4 int max = Integer.MIN_VALUE; 5 int sum = 0; 6 for(int i=0;i<A.length;i++){ 7 sum +=A[i]; 8 if(sum>max){ 9 max = sum; 10 } 11 if(sum<0){ 12 sum = 0; 13 } 14 } 15 return max; 16 } 17 }
View Code
What if multiply?
转载于:https://www.cnblogs.com/krunning/p/3538732.html
Maximum Subarray with Sum/ Multiply相关推荐
- Lintcode42 Maximum Subarray II solution 题解
[题目描述] Given an array of integers, find two non-overlapping subarrays which have the largest sum.The ...
- [LintCode] Maximum Subarray 最大子数组
Given an array of integers, find a contiguous subarray which has the largest sum. Notice The subarra ...
- [LeetCode] Maximum Subarray 最大子数组
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- [Lintcode]41. Maximum Subarray/[Leetcode]53. Maximum Subarray
41. Maximum Subarray/53. Maximum Subarray 本题难度: Eas Topic: Dynamic Programming Description Given an ...
- Leetcode-53 Maximum Subarray
#53. Maximum Subarray Find the contiguous subarray within an array (containing at least one number ...
- 53.Maximum Subarray
/** 53.Maximum Subarray * 2016-5-7 by Mingyang * 如果我们从头遍历这个数组.对于数组中的其中一个元素,它只有两个选择: 1.* 要么加入之前的数组加和之 ...
- LeetCode(53):Maximum Subarray
Maximum Subarray: Find the contiguous subarray within an array (containing at least one number) whic ...
- 【LeetCode】053. Maximum Subarray
题目: Find the contiguous subarray within an array (containing at least one number) which has the larg ...
- LeetCode: Maximum Subarray 解题报告
Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which ...
最新文章
- linux oracle 脚本,Linux的Oracle服务脚本
- 正则判断 手机邮箱的正确格式
- UNIX 网络协议的深度分析
- 死锁解决(oracle)
- Andorid App内部跟随熊语言改变
- SQL中CONVERT转化函数的用法[个人推荐]
- 求矩阵不靠边元素之和_机器(深度)学习数学知识之范数
- 无人机技术在精细建模中的应用(PPT)
- Android studio显示红叉,提示Error:please select android sdk
- sim卡没坏但苹果手机无服务_苹果8PLUS换壳导致无服务维修
- ScreenToGif录制录屏gif软件的推荐通用设置,优化使用体验
- 洛谷P1359租用游艇
- Unity人工智能之不断自我进化的五人足球赛
- 苹果系统 macOS Mojave 10.14.4上安装 Ubuntu 18.04 双系统
- Quartz 2D 涂鸦
- 八大基本数据类型(primitive type)
- Oracle函数获取汉字的首字母
- 逆元 与等比数列求和
- Broadcast 的使用
- 09年生日送我的煎蛋超级技术
热门文章
- Spring Cloud:查看注册到Eureka上的应用信息
- web实现远程桌面:Apache Guacamole
- typecho引入php文件,Typecho的functions.php
- html5家谱资源网,免费家谱系统(ASP,Access,CSS,html5)
- 重庆计算机二本专业有哪些专业,重庆高考计算机类分数线
- ajax删除成功后的回调,Ajax成功回调'删除'不触发在Firefox中
- python多进程优化_如何利用多进程优化Python视频应用
- 一行代码不用写,就可以训练、测试、使用模型,这个 star 量 1.5k 的项目帮你做到...
- 提前(qian)庆祝 “1024程序员节” ,价值 1500 元的京东卡免费送!
- 大家都在看的公众号是哪几个?