/*
面试题 01.01. 判定字符是否唯一
实现一个算法,确定一个字符串 s 的所有字符是否全都不同。
*/
public:
bool isUnique(std::string astr) {
bool unique = true;
std::vector<bool> book (26 * 2, false);
for (int i = 0; i < astr.length(); ++i)
{
auto index = astr[i] - 'A';
if (book[index])
{
unique = false;
break;
}
else
{
book[index] = true;
}
}
return unique;
}
LeetCode-面试题 01.01. 判定字符是否唯一
最新推荐文章于 2024-04-29 09:11:57 发布