国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

LeetCode:maximum-subarray

2019-11-08 02:42:19
字體:
供稿:網(wǎng)友

鏈接:https://www.nowcoder.com/PRactice/32139c198be041feb3bb2ea8bc4dbb01?tpId=46&tqId=29126&tPage=1&rp=1&ru=/ta/leetcode&qru=/ta/leetcode/question-ranking 來源:牛客網(wǎng)

題目描述

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. click to show more practice. More practice: If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.

class Solution {public: int maxSubArray(int A[], int n) { int v = 0; int result = INT_MIN; for(int i=0;i<n;++i) { v = max(v+A[i],A[i]); result = max(result,v); } return result; }};
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 万州区| 崇义县| 宜州市| 盘山县| 县级市| 吴川市| 永春县| 荆门市| 临沭县| 大连市| 施甸县| 隆安县| 云和县| 高邮市| 崇阳县| 商城县| 长沙县| 松滋市| 长兴县| 隆林| 博客| 台江县| 炎陵县| 永安市| 佛冈县| 镇沅| 饶河县| 班玛县| 胶南市| 越西县| 民乐县| 固阳县| 宁阳县| 安徽省| 无锡市| 卓资县| 马龙县| 溧水县| 伊宁县| 潮州市| 青海省|