File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change 3
3
public class MaxProduct {
4
4
public static int maxProduct (int [] A ) {
5
5
int max = 0 ;
6
-
7
- int left = 0 ;
8
- int right = 0 ;
9
-
6
+
10
7
int len = A .length ;
11
8
12
9
int product = 1 ;
@@ -15,11 +12,13 @@ public static int maxProduct(int[] A) {
15
12
if (A [i ] <= 0 ) {
16
13
max = Math .max (max , product );
17
14
product = 1 ;
15
+ continue ;
18
16
}
17
+
19
18
product *= A [i ];
20
19
}
21
20
22
- return 0 ;
21
+ return max ;
23
22
}
24
23
25
24
/*
Original file line number Diff line number Diff line change
1
+ package Algorithms .array ;
2
+
3
+ public class RemoveDuplicates {
4
+ public int removeDuplicates (int [] A ) {
5
+ if (A == null || A .length == 0 ) {
6
+ return 0 ;
7
+ }
8
+
9
+ // A里至少有1个元素
10
+ int len = 1 ;
11
+
12
+ for (int i = 1 ; i < A .length ; i ++) {
13
+ if (A [i ] != A [i - 1 ]) {
14
+ A [len ++] = A [i ];
15
+ }
16
+ }
17
+
18
+ return len ;
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments