10000 3 · threec/leetcode@d5d2eee · GitHub
[go: up one dir, main page]

Skip to content

Commit d5d2eee

Browse files
committed
3
1 parent fd3228a commit d5d2eee

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
int maxProduct(int A[], int n) {
4+
if (n == 0) {
5+
return 0;
6+
}
7+
int result = A[0];
8+
int premax = A[0];
9+
int premin = A[0];
10+
for (int i = 1; i < n; i++) {
11+
int heremax = max(A[i], max(A[i] * premax, A[i] * premin));
12+
int heremin = min(A[i], min(A[i] * premax, A[i] * premin));
13+
result = max(result, heremax);
14+
premax = heremax;
15+
premin = heremin;
16+
}
17+
return result;
18+
}
19+
};

0 commit comments

Comments
 (0)
0