测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A66830. 下面schedule函数的时间复杂度为( )。1 #include <algorithm>

单选题

题目描述

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

1 #include <algorithm>
2 using namespace std;
3 struct activity {
4  int id, start, end;
5 };
6 bool compare(activity a, activity b) {
7  return a.end < b.end;
8 }
9 int schedule(int n, activity * p) {
10  sort(p, p + n, compare);
11  int cnt = 0, end = 0;
12  for (int i = 0; i < n; i++) {
13   if (p[i].start >= end) {
14    end = p[i].end;
15    cnt++;
16   }
17  }
18  return cnt;
19 }

选项(单选)