使用统计学的方法:O(n)
分治的方法,比较复杂
class Solution {
public:
int maxSubArray(int A[], int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int maxendinghere=A[0];
int max = maxendinghere;
for(int i=1;i<n;i++) {
if (maxendinghere > 0) {
maxendinghere = maxendinghere + A[i];
} else {
maxendinghere = A[i];
}
if (maxendinghere > max) {
max = maxendinghere;
}
}
return max;
}
};
分享到:
相关推荐
LeetCode-Questions:示例回购包含一些leetcode问题的答案
leetcode的题目:Balanced Binary Tree
leetcode 答案leetcode_questions 把 Leetcode 问题和答案放在这里
Leetcode_questions 目前拥有: 简单的: 1.二和(c) 7.反转整数(c) 9.回文数(c) 14.最长公共前缀(python) 20.有效括号(python) 21.合并两个排序列表(c) 26.从排序数组中删除重复项 (c) 27.删除元素(c) 28.实现...
leetcode卡 :dizzy: LeetCode for Python :snake: Requirements Python >= 3.8 Installation git clone git@github.com:imajinyun/leetcode-python.git cd leetcode-python Usage python3 -m unittest discover -s ....
leetcode 316 算法 这是一个算法问题列表。 力码 LeetCode #1:二和 LeetCode #2:两个数字相加 LeetCode #5:最长回文子串 力扣#15:3Sum LeetCode #20:有效括号 LeetCode #21:合并两个排序列表 LeetCode #24:成...
leetcode数组下标大于间距 :dizzy: LeetCode for PHP :elephant: Requirements PHP >= 8.0 PHPUnit >= 9.5 Installation Install the package through . Run the Composer require command from the Terminal: git ...
leetcode 2 leetcode_prelude 在 LeetCode 中练习的一些有用的宏和定义。 如何使用 将以下行添加到您的 Cargo.toml。 [ dependencies ] leetcode_prelude = " ^0.2 " 例子 二叉树初始化 use leetcode_prelude :: ...
leetcode 答案Leetcode-问题 Leetcode 问题列表和答案
LeetCode 101:和你一起你轻松刷题(C++)
LEETCODE 问题 欢迎来到解决 200 个 Leetcode 问题频道。 请不要忘记给这个 repo 一个 Star :star: 加入我们的 Discord 社区,获得每日 LeetCode 挑战—— 如何贡献? 这个频道是关于什么的? 这是一个学习小组,...
leetcode 答案LeetCode 问题的思考过程 在这个 repo 中,我对一些 LeetCode 问题提出了思考过程以及易于理解的图表。 我还在 LeetCode 上链接了我的原始答案。 问题: 跳跃游戏 二叉树最大路径和 解码方式 叶相似树 ...
vscode提交leetcode leetcodeSolutionsPython 这些是 leetcodes 库的 python 解决方案。 Leetcode 是一种很棒的方式来练习编写面试的套路。 这是我的母语python3的解决方案集合。 这些解决方案是使用 leetcode 插件...
leetcode怎么销号 LeetCode-Solutions :green_heart:My own LeetCode solutions ...Subarray Easy 动态规划 0069 Sqrt(x) Easy 二分、牛顿迭代 0070 Climbing Stairs Easy 动态规划 0075 Sort Colors M
leetcode 答案 leetCode :keyboard:我的 Leetcode 解题答案
Maximum Gap: Something about largest-rectangle-in-histogram: 最长递增子序列: 最长公共自序列: Something about: best time to buy and sell stack: 单链表中的环,两个单链表的公共点。 populating-next-...
leetcode 答案LeetCode-问题 这些是我过去做过的各种 LeetCode 问题的答案
leetcode_101:LeetCode 101:和你一起你轻松刷题(C ++)
leetcode 分类 LeetCode :bouquet::bouquet::bouquet: 介绍 leetcode 题解,Issues 会记录 leetcode 解题之路,并使用 label 进行了分类。 目录 链表
加油站问题leetcode LeetCode LeetCode-JS分类列表: :smiling_face_with_smiling_eyes: :flushed_face: :winking_face: :face_with_tongue: :face_with_open_mouth: :beaming_face_with_smiling_...