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

首頁 > 學院 > 開發設計 > 正文

LeetCode:

2019-11-08 02:41:39
字體:
來源:轉載
供稿:網友

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

題目描述

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; vector<int>v; for(int i=0;i<n;++i) { v.push_back(0); } v[0] = A[0]; int result = A[0]; for(int i=1;i<n;++i) { v[i] = max(v[i-1]+A[i],A[i]); result = max(result,v[i]); } return result; }};
上一篇:C--最短路

下一篇:hdu 1157排序

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 内江市| 安宁市| 大城县| 拉萨市| 当雄县| 桓台县| 田林县| 志丹县| 沈阳市| 樟树市| 开封县| 奉新县| 泽州县| 墨竹工卡县| 黔南| 宣汉县| 蕉岭县| 栖霞市| 武安市| 武隆县| 沈阳市| 孟津县| 山东省| 正定县| 云阳县| 乡宁县| 土默特左旗| 洞头县| 巴林左旗| 沙雅县| 油尖旺区| 紫金县| 兴隆县| 武川县| 仁怀市| 娄烦县| 滦平县| 策勒县| 青龙| 繁峙县| 石泉县|