1.1 Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures?
判断一个单词中是否存在相同字母
#include <iostream> #include <string> using namespace std; int unique(const string& a) { bool boola[255]={0}; for (int i=0;i<a.length();i++) { int b = (int)a[i]; if(1==boola[b]) return 1; else boola[b]=1; } return 0; } int main() { string a ="abcdefghijklmn"; cout<<unique(a); }