国产探花免费观看_亚洲丰满少妇自慰呻吟_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排序

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 专栏| 永川市| 平安县| 密云县| 南召县| 墨竹工卡县| 都昌县| 九龙城区| 林州市| 施秉县| 全椒县| 周宁县| 大城县| 灵寿县| 申扎县| 隆安县| 光泽县| 乌苏市| 长宁区| 陇西县| 疏附县| 城步| 北票市| 宁阳县| 柳河县| 虹口区| 土默特左旗| 满城县| 阜南县| 廊坊市| 清涧县| 高青县| 富阳市| 涿州市| 乌恰县| 阳曲县| 香河县| 白银市| 孝感市| 乌兰浩特市| 武夷山市|