We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b7d3488 commit 8061774Copy full SHA for 8061774
Sorted-Array/MaxSum
@@ -0,0 +1,30 @@
1
+// 把题目读错了,人家求连续的(contiguous)的乘积,我TMD的算成了求和,一个array里面subarray和最大的,O(n)的思路如下:
2
+
3
+class Solution {
4
+public:
5
+ int maxProduct(int A[], int n) {
6
+ int sum = 0;
7
+ int curMax = 0, temMax = 0;
8
+ bool flag = true;
9
+ for(int i = 0;i < n;i++)
10
+ {
11
+ if(flag)
12
13
+ if(temMax + A[i] >= temMax)
14
+ temMax = temMax + A[i];
15
+ else
16
17
+ flag = false;
18
+ curMax = max(temMax,curMax);
19
+ }
20
21
22
23
+ flag = true;
24
+ temMax = A[i];
25
26
27
+ return curMax;
28
29
30
+};
0 commit comments