下面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 }
0(n)
o(log(n) )
O(nlog(n))
0(n2)