单选题 适中
#21413

下面 schedule 函数的时间复杂度为( )。 # include <algorithm> using namespace std ; struct act…

下面 schedule 函数的时间复杂度为(   )。

#include <algorithm>
using namespace std;
struct activity {
	int id, start, end;
};
bool compare(activity a, activity b) {
	return a.end < b.end;
}
int schedule(int n, activity * p) {
	sort(p, p + n, compare);
	int cnt = 0, end = 0;
	for (int i = 0; i < n; i++) {
		if (p[i].start >= end) {
			end = p[i].end;
			cnt++;
		}
	}
	return cnt;
}
未登录也能判分,登录后才会记录
答案与解析
正确答案:C
这道题暂未补解析。