单选题
下面 schedule 函数的时间复杂度为( )。
#includeusing namespace std;struct activity {\tint id, start, end;};bool compare(activity a, activity b) {\treturn a.end < b.end;}int schedule(int n, activity * p) {\tsort(p, p n, compare);\tint cnt = 0, end = 0;\tfor (int i = 0; i < n; i ) {\t\tif (p[i].start >= end) {\t\t\tend = p[i].end;\t\t\tcnt ;\t\t}\t}\treturn cnt;}
A.
O(n)
B.
O(log(n))
C.
O(nlog(n))
D.
O(n2)
发表评论 取消回复