[LeetCode] Maximum Subarray
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
.
If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.
1 class Solution { 2 public: 3 int maxSubArray(int A[], int n) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 int ret = INT_MIN; 7 int sum = 0; 8 for(int i = 0; i < n; i++) 9 { 10 sum = max(sum + A[i], A[i]); 11 ret = max(sum, ret); 12 } 13 14 return ret; 15 } 16 };
[LeetCode] Maximum Subarray相关推荐
- [LeetCode] Maximum Subarray 最大子数组
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- LeetCode: Maximum Subarray 解题报告
Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which ...
- LeetCode Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- LeetCode - Maximum Subarray
题目: Find the contiguous subarray within an array (containing at least one number) which has the larg ...
- LeetCode: Maximum Subarray
自己想得太复杂了,网上查了别人的代码..太简单了.. 1 class Solution { 2 public: 3 int maxSubArray(int A[], int n) { 4 // Sta ...
- 【DP】LeetCode 53. Maximum Subarray
LeetCode 53. Maximum Subarray Solution1:我的答案 动态规划 class Solution { public:int maxSubArray(vector< ...
- 【动态规划】LeetCode 53. Maximum Subarray
LeetCode 53. Maximum Subarray 原题描述(求子序列最大和/最大子串):Find the contiguous subarray within an array (conta ...
- [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
Maximum Subarray: Find the contiguous subarray within an array (containing at least one number) whic ...
最新文章
- stat用法:获取文件对应权限的数字
- StackOverflow 上面最流行的 7 个 Java 问题!
- App.config/Web.config 中特殊字符的处理
- Angular module加载的原理研究
- 04-课后作业1-字符串加密
- java activit怎么画图_Activiti 快速入门指南(用Java编写服务任务)
- c++代码健壮性_复活Navex-使用图查询进行代码分析(上)
- 微信公众号服务器模式,微信公众平台的两种模式
- oracle 表的移动,oracle 表移动表空间
- 电脑html游戏,电脑网页游戏排行榜
- liunx服务器间拷贝文件,linux 不同服务器之间拷贝文件
- Scikit-learn:分类classification
- The host '192.168.174.130' is unreachable. the host may be down..............
- javascript无提示关闭窗口,兼容IE,Firefox
- spring教程笔记5
- fiddler4使用教程
- java嵌入式软件开发工程师_嵌入式软件工程师笔试题
- 【分享】地产集团公司LOGO设计
- 找工作时,如何区分对方是不是培训机构?
- 送书 |《Python数据分析从小白到专家》
热门文章
- 索尼发布全球首款内置AI传感器,1200万像素,660元起售
- 马斯克因何财报会议怒爆粗口?明明是史上最佳Q1业绩,股价还一度大涨10%
- 在任天堂Switch上倒贴30块钱“加班”,我一个程序员还觉得很刺激
- 华为云HiLens Kit上手初探:一款几乎“零门槛”的AI开发套件
- 阿里AI再揽2员大将:挖角高通、360,年薪百万美元
- 不忘初心,努力做最好的自己
- ecshop仿淘宝加入购物车弹出框【支持任何页面】淡出淡隐固定屏幕-兼容ie
- HDU-1128 Self Numbers 筛选
- 筑业和恒智天成哪个好_浙江新闻客户端:废弃物变身创意作品 天成小学垃圾分类工作有声有色...
- 写个测试程序测试下,单片机使用浮点型数效率有多低