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

Commit 7897a56

Browse files
committed
cover max
1 parent 7e0ecc8 commit 7897a56

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

‎src/main/java/grey/algorithm/code11_heap/Code_0005_NowCoder_LineCoverMax.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,25 @@ public static void main(String[] args) {
2323
}
2424

2525
// 暴力解
26+
// 也可以通过牛客测试
2627
// lines[i][0]: 第i条线的起始点
2728
// lines[i][0]: 第i条线的终点
2829
// 时间复杂度O(n*(max - min))
2930
public static int maxCover(int[][] lines) {
30-
if(null == lines || lines.length == 0) {
31+
if(null == lines || lines.length < 1) {
3132
return 0;
3233
}
3334
int min = lines[0][0];
3435
int max = lines[0][1];
3536
for (int i = 1; i < lines.length; i++) {
36-
min = Math.min(min, lines[i][0]);
37-
max = Math.max(max, lines[i][1]);
37+
min = Math.min(lines[i][0],min);
38+
max = Math.max(lines[i][1],max);
3839
}
3940
int maxCover = 0;
40-
for (int i = min; i <= max; i++) {
41+
for (int i = min; i <= max; i++) {
4142
int cover = 0;
4243
for (int[] line : lines) {
43-
if (i >= line[0] && i <= line[1]){
44+
if (line[0] <= i&& i <= line[1]){
4445
cover++;
4546
}
4647
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /