您的位置:首页 > 其它

百度移动终端研发工程师笔试题

2013-03-07 19:38 330 查看
写一个字符串逆序的程序,时间复杂度和空间复杂度最低,效率越高越好。不知道下面的代码的时空开销几何,有更好的方法请指教。

#include "stdafx.h"
#include "string.h"
void resere(char a[])
{
int len=strlen(a);
char temp;
int i=0,j=len-1;
while(i<len/2)
{
temp=a[i];
a[i++]=a[j];
a[j--]=temp;
}
}

int main()
{
char a[]={"hello world"};
resere(a);
printf("%s ",a);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: