warmingtxdy
1 void reverse( string &s ){
2     int n = s.size();
3     for(int i = 0 ; i < n/2 ; i++ )//这个循环走了n/2次,所以O(n)
4         swap( s[i] , s[n-1-i] );
5 }
1 int count = 1;      
2 while (count < n){//cout*2^x=n,x=logn,所以O(logn)
3    count = count * 2;
4 }
1 int i, j;      
2 for(i = 1; i < n; i++)//n^3
3     for(j = 1; j < n; j++)
4         for(j = 1; j < n; j++){
5                ......
6         }
1 int i, j;      
2 for(i = 0; i < n; i++){//n^2
3     for(j = i; j < n; j++){   
4         .....
5     }
6 }
1 for(int i=2;i*i<=n;i++){//sqrt(n)
2     ....
3 }

 

分类:

技术点:

相关文章:

  • 2022-01-01
  • 2021-07-07
  • 2021-12-27
  • 2022-01-08
  • 2021-11-13
  • 2021-07-12
  • 2021-12-23
猜你喜欢
  • 2021-12-19
  • 2021-12-09
  • 2021-12-04
  • 2021-04-01
  • 2022-02-21
  • 2022-01-01
  • 2021-12-08
相关资源
相似解决方案