用 for 循环的复杂度毫无疑问是 O(n)
for(int i=1,j=n;i<=j;i++,j--){
if(i==j) cout<<a[i]<<" ";
else cout<<a[i]<<" "<<a[j]<<" ";
}
可是递归写法
void maxx(int n){
if(n==1){
cout<<a[n]<<" ";
return;
}
cout<<a[n]<<" ";
maxx(n-2);
cout<<a[n-1]<<" ";
}
的复杂度我认为也是 O(n) 为什么二者时间大有不同?