MCPcopy Create free account
hub / github.com/algorithmzuo/algorithm-journey / compute

Method compute

src/class027/Code02_MaxCover.java:46–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44 }
45
46 public static int compute() {
47 // 堆的清空
48 size = 0;
49
50 // 线段一共有n条,line[0...n-1][2] : line[i][0] line[i][1], 左闭右闭
51 // 所有线段,根据开始位置排序,结束位置无所谓
52 // 比较器的用法
53 // line [0...n) 排序 : 所有小数组,开始位置谁小谁在前
54 Arrays.sort(line, 0, n, (a, b) -> a[0] - b[0]);
55 int ans = 0;
56 for (int i = 0; i < n; i++) {
57 // i : line[i][0] line[i][1]
58 while (size > 0 && heap[0] <= line[i][0]) {
59 pop();
60 }
61 add(line[i][1]);
62 ans = Math.max(ans, size);
63 }
64 return ans;
65 }
66
67 // 小根堆,堆顶0位置
68 public static int[] heap = new int[MAXN];

Callers 1

mainMethod · 0.95

Calls 4

popMethod · 0.95
addMethod · 0.95
sortMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected