国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 甘孜| 会东县| 武冈市| 华亭县| 清涧县| 凭祥市| 江川县| 北碚区| 阿拉善左旗| 吉安县| 南郑县| 大同市| 鄄城县| 崇信县| 丰台区| 大同县| 子长县| 石楼县| 万荣县| 苏尼特左旗| 神农架林区| 广南县| 绥滨县| 皋兰县| 郎溪县| 高平市| 蒲城县| 和田县| 翼城县| 邵阳县| 河北省| 讷河市| 静安区| 威海市| 广汉市| 广宗县| 宁安市| 达州市| 东至县| 大余县| 乐陵市|