您的位置:首页 > 其它

YY笔试题: 输出一个字符串中没有重复的字符。如“baaca”输出“bac”

2014-12-24 22:50 316 查看
O(1)的空间复杂度 O(n)的时间复杂度;
int 类型4个字节 32位(64位机),能够表示26个英文字母
</pre><pre code_snippet_id="561590" snippet_file_name="blog_20141224_4_2056114" name="code" class="cpp">
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define getBit(x) (1<<x-'a')

void shuchu(char *s)
{
int dictionary=0;
int length=strlen(s);
for(int i=0;i<length;i++)
{
if(dictionary!=(dictionary | getBit(s[i])))
{
dictionary |=getBit(s[i]);
printf("%c",s[i]);
}
}
}

int main()
{
char *s="baaca";
shuchu(s);
printf("\n");
return 0;
}
</pre><pre>


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐