cracking the coding interview No1.1

来源:互联网 发布:数据库存储过程优点 编辑:程序博客网 时间:2024/05/18 20:06


1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannnot use additional data structures?


bool isUnique(char *str){int hash[256];memset(hash,0,sizeof(hash));if (str == NULL){return false;}while (*str != '\0'){if(hash[*str]){return false;}hash[*str] = 1;str++;}return true;}

0 0
原创粉丝点击