1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structure?
bool isUniqueChar(string s) {
vector<bool> c(256, false);
for (int i = 0; i < s.length(); i++) {
if (c[s[i]])
return false;
c[s[i]] = true;
}
return true;
}
本文介绍了一种用于确定字符串是否包含全部唯一字符的算法,并提供了一个具体的实现示例。该算法通过使用布尔型向量来跟踪已出现的字符,从而避免了使用额外的数据结构。
739

被折叠的 条评论
为什么被折叠?



