Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitec77e43

Browse files
committed
remove duplicate
1 parentd1c27bd commitec77e43

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

‎array/MaxProduct.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
publicclassMaxProduct {
44
publicstaticintmaxProduct(int[]A) {
55
intmax =0;
6-
7-
intleft =0;
8-
intright =0;
9-
6+
107
intlen =A.length;
118

129
intproduct =1;
@@ -15,11 +12,13 @@ public static int maxProduct(int[] A) {
1512
if (A[i] <=0) {
1613
max =Math.max(max,product);
1714
product =1;
15+
continue;
1816
}
17+
1918
product *=A[i];
2019
}
2120

22-
return0;
21+
returnmax;
2322
}
2423

2524
/*

‎array/RemoveDuplicates.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
packageAlgorithms.array;
2+
3+
publicclassRemoveDuplicates {
4+
publicintremoveDuplicates(int[]A) {
5+
if (A ==null ||A.length ==0) {
6+
return0;
7+
}
8+
9+
// A里至少有1个元素
10+
intlen =1;
11+
12+
for (inti =1;i <A.length;i++) {
13+
if (A[i] !=A[i -1]) {
14+
A[len++] =A[i];
15+
}
16+
}
17+
18+
returnlen;
19+
}
20+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp