时间复杂度
int count=0;
for(int k=0;k<100;k++){
count++;
}
cout<<count;
//程序执行次数:100
//时间复杂度:O(1)
int count=0;
for(int k=0;k<*N;k++){
count++;
}
int M=10;
while(M--){
count++;
}
cout<<count;
//程序执行次数:2*n+m 2*n+10
//时间复杂度:O(n)
int count=0;
for(int k=0;k<M;k++){
count++;
}
for(int k=0;k<N;k++){
count++;
}
cout<<count;
//【注】时间复杂度为O(N+M);如果给出N远大于M,就可以写成O(N)或者O(M);该代码什么都没有给,所以是O(M+N);
//程序执行次数:M+N
//时间复杂度:
while(*str){
if(*str==character)
return str;
else
str++;
}
//程序执行次数:N
//时间复杂度:O(N)

浙公网安备 33010602011771号