classSolution { public: interaseOverlapIntervals(vector<vector<int>>& intervals){ int n = intervals.size(); if (intervals.empty() || n == 1) { return0; } sort(intervals.begin(), intervals.end(), [](vector<int> a, vector<int> b) { return a[1] < b[1]; });
int total = 0, prev = intervals[0][1]; for (int i = 1; i < n; ++i) { if (intervals[i][0] < prev) { ++total; } else { prev = intervals[i][1]; } } return total; } };
int n = intervals.size(); int right = intervals[0][1]; int ans = 1; for (int i = 1; i < n; ++i) { if (intervals[i][0] >= right) { ++ans; right = intervals[i][1]; } } return n - ans; } };