We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b4a38fb commit 820a10fCopy full SHA for 820a10f
动态规划系列/贪心算法之区间调度问题.md
@@ -72,9 +72,15 @@ int intervalSchedule(int[][] intvs) {}
72
public int intervalSchedule(int[][] intvs) {
73
if (intvs.length == 0) return 0;
74
// 按 end 升序排序
75
- Arrays.sort(intvs, new Comparator<int[]>() {
+ Arrays.sort(points, new Comparator<int[]>() {
76
+ @Override
77
public int compare(int[] a, int[] b) {
- return a[1] - b[1];
78
+ // 这里不能使用 a[1] - b[1],要注意溢出问题
79
+ if (a[1] < b[1])
80
+ return -1;
81
+ else if (a[1] > b[1])
82
+ return 1;
83
+ else return 0;
84
}
85
});
86
// 至少有一个区间不相交
0 commit comments